cache / cache
Library of all the php-cache adapters
Requires
- php: ^8.2
- doctrine/cache: ^2.2
- league/flysystem: ^2.0 || ^3.0
- psr/cache: ^3.0
- psr/log: ^3.0
- psr/simple-cache: ^2.0 || ^3.0
Requires (Dev)
- cache/integration-tests: ^1.0.4@dev
- defuse/php-encryption: ^2.4
- illuminate/cache: ^11.0 || ^12.0 || ^13.0
- mockery/mockery: ^1.6
- mongodb/mongodb: ^2.0
- php-cs-fixer/shim: 3.95.19
- phpstan/phpstan: 2.2.8
- phpunit/phpunit: ^11.5
- predis/predis: ^2.0 || ^3.0
- symfony/cache: ^7.4 || ^8.0
- symfony/clock: ^7.4 || ^8.0
Suggests
- ext-apcu: APCu extension is required to use the APCu Adapter
- ext-memcache: Memcache extension is required to use the Memcache Adapter
- ext-memcached: Memcached extension is required to use the Memcached Adapter
- ext-mongodb: Mongodb extension required to use the Mongodb adapter
- ext-redis: Redis extension is required to use the Redis adapter
- defuse/php-encryption: Required to use the encryption cache decorator
- mongodb/mongodb: Mongodb lib required to use the Mongodb adapter
Provides
- psr/cache-implementation: 3.0
- psr/simple-cache-implementation: 2.0 || 3.0
Conflicts
None
Replaces
- cache/adapter-common: 3.0.0
- cache/apcu-adapter: 3.0.0
- cache/array-adapter: 3.0.0
- cache/chain-adapter: 2.1.0
- cache/doctrine-adapter: 3.0.0
- cache/encryption-cache: 2.1.0
- cache/filesystem-adapter: 3.0.0
- cache/hierarchical-cache: 2.1.0
- cache/illuminate-adapter: 2.0.0
- cache/memcache-adapter: 3.0.0
- cache/memcached-adapter: 3.0.0
- cache/mongodb-adapter: 3.0.0
- cache/namespaced-cache: 2.0.4
- cache/predis-adapter: 3.0.0
- cache/prefixed-cache: 2.0.4
- cache/psr-6-doctrine-bridge: 4.0.4
- cache/redis-adapter: 3.0.0
- cache/session-handler: 2.0.4
- cache/simple-cache-bridge: 2.0.4
- cache/tag-interop: 2.0.0
- cache/taggable-cache: 3.0.0
- cache/util: 1.0.4
- cache/void-adapter: 3.0.0
README
PHP Cache provides PSR-6 and PSR-16 cache adapters, decorators, and integration tools. This repository contains the packages in the PHP Cache organization.
Requirements
Version 3 requires PHP 8.2 or later and psr/cache 3.x. Packages that implement PSR-16 support psr/simple-cache 2.x and 3.x.
Some adapters also need a PHP extension or client library. Composer lists those requirements for each split package.
Installation
Install the package for the backend you use:
composer require cache/redis-adapter:^3.0
You can install every adapter and library through the aggregate package:
composer require cache/cache:^3.0
See the shared documentation for adapter features and examples.
Upgrading to version 3
The Redis and Predis adapters now store tag indexes as expiry-aware sorted sets under a reserved key prefix. Version 2 uses Redis sets under different keys.
All concrete adapters now store a generation snapshot with each tagged item. They also store a generation marker for each tag. The common adapters use portable SHA-256-based metadata keys. The item payload and marker make stale entries miss after invalidation.
Filesystem Adapter 3 hashes keys into shard directories instead of using raw cache keys as filenames.
Public cache keys that start with tag! or tagv! are reserved for tag metadata in cache/adapter-common 3.
Stop or drain all workers, clear each shared cache, and then deploy version 3. Follow the same sequence before a rollback. Do not run version 2 and 3 workers against the same cache.
Upgrading to version 2
Version 2 removes the APC adapter. Use cache/apcu-adapter instead.
APCu entries now use native arrays. Redis and Predis tag indexes now use sets instead of lists. Older workers cannot safely share these stores with version 2 workers.
NamespacedCachePool now encodes namespace bytes outside [A-Za-z0-9_.] and literal lowercase _x sequences. Public keys only encode structural | and ! bytes and literal lowercase _x sequences. Clear affected namespaced caches before an upgrade or rollback when these transformed values are present.
Custom adapters extending AbstractCachePool must add the PHP 8 and PSR-3 method signatures used by version 2. The Filesystem adapter now supports Flysystem 2 and 3, the Illuminate adapter supports Illuminate 11 through 13, and the Predis adapter supports Predis 2 and 3. Flysystem 1 and older client releases are no longer supported.
Use this sequence for an upgrade or rollback:
- Stop or drain every worker that uses the affected cache.
- Clear each affected APCu, Redis, Predis, or namespaced cache store.
- Deploy the target version and restart the workers.
Contributing
Read CONTRIBUTING.md before opening a pull request. Report cache package issues on the GitHub issue tracker.