cache / array-adapter
A PSR-6 cache implementation using a php array. This implementation supports tags
Requires
- php: ^8.2
- cache/adapter-common: ^3.0
- cache/hierarchical-cache: ^2.1
- psr/cache: ^3.0
- psr/simple-cache: ^2.0 || ^3.0
Requires (Dev)
- cache/integration-tests: ^1.0@dev
- phpunit/phpunit: ^11.5
Provides
- psr/cache-implementation: 3.0
- psr/simple-cache-implementation: 2.0 || 3.0
README
This package provides in-memory PSR-6 and PSR-16 cache implementations. The pool supports tags and hierarchical keys.
Values live only for the current PHP process. This adapter works well in tests and short-lived scripts.
Installation
composer require cache/array-adapter:^3.0
Usage
use Cache\Adapter\PHPArray\ArrayCachePool; $pool = new ArrayCachePool();
Limit stored items
Pass a positive maximum item count as the first constructor argument. The default null value keeps every item for the process lifetime.
$pool = new ArrayCachePool(1_000);
When the pool reaches the limit, saving a new key removes the key in the next storage slot. Updating an existing key keeps its slot.
Upgrading to version 3
Version 3 stores a generation snapshot with each tagged item and a separate marker for each tag. Array caches are process-local, so new workers start with an empty cache.
Contributing
Send pull requests to the main repository. Report issues on the GitHub issue tracker.