cache / encryption-cache
Adds encryption support to your PSR-6 cache implementation
2.1.0
2026-08-20 01:59 UTC
Requires
- php: ^8.2
- cache/adapter-common: ^2.0.3 || ^3.0
- cache/tag-interop: ^2.0
- defuse/php-encryption: ^2.4
- psr/cache: ^3.0
Requires (Dev)
- cache/array-adapter: ^3.0
- cache/filesystem-adapter: ^3.0
- cache/integration-tests: ^1.0@dev
- phpunit/phpunit: ^11.5
README
This package encrypts values stored through a taggable PSR-6 cache pool. Encryption adds CPU and storage overhead, so use it only when cached values need protection at rest.
Installation
composer require cache/encryption-cache:^2.1
Usage
use Cache\Adapter\PHPArray\ArrayCachePool; use Cache\Encryption\EncryptedCachePool; use Defuse\Crypto\Key; $key = Key::createNewRandomKey(); $pool = new EncryptedCachePool(new ArrayCachePool(), $key); $item = $pool->getItem('account.42'); $item->set(['email' => 'user@example.com']); $pool->save($item);
The wrapped pool must implement TaggableCacheItemPoolInterface. Persist the encryption key outside the cache and load the same key for every request.
Version 2.1 supports cache/adapter-common 2 and 3. Follow the wrapped adapter's upgrade steps before deploying or rolling back.
Contributing
Send pull requests to the main repository. Report issues on the GitHub issue tracker.