CacheLayer is a standalone cache toolkit for modern PHP applications. It provides a unified API over PSR-6 and PSR-16 with local, distributed, and cloud adapters.
CacheLayer was separated from the existing Intermix project to improve package visibility, maintenance focus, and faster feature enrichment for caching.
- Unified
Cachefacade implementing PSR-6, PSR-16,ArrayAccess, andCountable - Adapter support for APCu, File, PHP Files, Memcached, Redis, Redis Cluster, PDO (SQLite default), Shared Memory, MongoDB, DynamoDB, and S3
- Tagged invalidation with versioned tags:
setTagged(),invalidateTag(),invalidateTags() - Stampede-safe
remember()with pluggable lock providers - Per-adapter metrics counters and export hooks
- Payload compression controls
- Value serializer helpers for closures/resources
- Memoization helpers:
memoize(),remember(),once()
- PHP 8.3+
- Composer
Optional extensions/packages depend on adapter choice:
ext-apcuext-redisext-memcachedext-pdo+ driver (pdo_sqlite,pdo_pgsql,pdo_mysql, ...)ext-sysvshmmongodb/mongodbaws/aws-sdk-php
composer require infocyph/cachelayeruse Infocyph\CacheLayer\Cache\Cache;
$cache = Cache::pdo('app'); // defaults to sqlite file under sys temp cachelayer/pdo
$cache->setTagged('user:1', ['name' => 'Ada'], ['users'], 300);
$user = $cache->remember('user:1', function ($item) {
$item->expiresAfter(300);
return ['name' => 'Ada'];
}, tags: ['users']);
$cache->invalidateTag('users');
$metrics = $cache->exportMetrics();CacheLayer includes optional payload/serialization hardening controls:
$cache
->configurePayloadSecurity(
integrityKey: 'replace-with-strong-secret',
maxPayloadBytes: 8_388_608,
)
->configureSerializationSecurity(
allowClosurePayloads: false,
allowObjectPayloads: false,
);You can also set:
CACHELAYER_PAYLOAD_INTEGRITY_KEYCACHELAYER_MAX_PAYLOAD_BYTES
See SECURITY.md for deployment guidance and threat model notes.
https://docs.infocyph.com/projects/CacheLayer
composer test:codeOr run the full test pipeline:
composer test:allContributions are welcome.
- Open an issue for bug reports or feature discussions
- Open a pull request with focused changes and tests
- Keep coding style and static checks passing before submitting
MIT License. See LICENSE.