CacheLayer Manual#

CacheLayer is a standalone caching toolkit for PHP 8.3+ with:

  • PSR-6 and PSR-16 support behind one facade (Cache)

  • local, distributed, and cloud cache adapters

  • generation-tag invalidation (setTagged, invalidateTag, invalidateTags)

  • stampede-resistant remember() with bounded pluggable locks

  • adapter-level metrics export hooks

  • payload compression controls

  • Closure-only serialization through Opis Closure

  • process-local memoization helpers (memoize, remember, once)

Project Background#

CacheLayer was separated from the existing Intermix project for better package visibility and focused feature enrichment around caching.

How to Use This Manual#

  1. Start with cache for the unified API and factory overview.

  2. Read adapters/index to choose a backend and copy its example.

  3. Follow cookbook for complete end-to-end process flows.

  4. Use metrics-and-locking for production visibility and stampede control.

Quick Start#

use Infocyph\CacheLayer\Cache\Cache;

$cache = Cache::memory('app');

$profile = $cache->remember(
    'user.42',
    fn () => ['id' => 42, 'name' => 'Ada'],
    ttl: 300,
    tags: ['users'],
);

$cache->invalidateTag('users');