The PHP Cache organization is dedicated to providing solid, powerful, flexible, and lightweight caching libraries for PHP projects. All of the adapters we have created are PSR-6 compliant. If you are a library implementer, we even have a repository of tests to help you meet the PSR-6 specification.
Below you will find information about what features our libraries offer, and what adapters we have. You can also find out framework integration libraries.
If you are new to PSR-6 caching you may want to have a look at our introduction.
Cache pool implementations¶
There are plenty of adapters in this organisaion. Each of them lives in a different repository. Splitting them up in multiple packages complies with the Common reuse principle and makes it easier for the developer to follow the changes of a specific adapter.
Each adapter has it own features. The table below lists all our adapters and their features.
|Couchbase (via Doctrine)||Yes||No|
|Filesystem (via Flysystem)||Yes||No|
|Riak (via Doctrine)||Yes||No|
|SQLite3 (via Doctrine)||Yes||No|
|WinCache (via Doctrine)||Yes||No|
|Xcache (via Doctrine)||Yes||No|
|ZendData (via Doctrine)||Yes||No|
* Hierarchy store lots of extra items in cache that are never actively removed. Some implementations of cache storages like Redis and Memcache will automatically remove these items when they're stale or no longer used. That is why hierarchy will work better on such cache storages.
We also have a chain adapter where you can chain multiple pool together. It is great if you have a fast storage with limited memory and a slower storage with loads of memory.
The doctrine adapter is a PSR-6 adapter that wraps a
Doctrine\Common\Cache\Cache object. With this adapter you can use storages like Riak and WinCache which currently do not have any PHP Cache adapters.
Use composer to install any of the adapters above. Some adapters may require configuration before they can be used. Refer to the adapter's Github page to see how they are configured. You could also use the Symfony AdapterBundle to configure the adapters.
composer require cache/[any]-adapter
You can also install all of the adapters with the
composer require cache/cache
Unless other is specified, all adapters support PHP version
^7.0. Most adapters do also have requirements
on PHP extension. Like the Redis adapter requires
Tags is used to control the invalidation of items.
$item = $pool->getItem('tobias'); $item->set('value')->setTags(['tag0', 'tag1']) $pool->save($item); $item = $pool->getItem('aaron'); $item->set('value')->addTag('tag0'); $pool->save($item); // Remove everything tagged with 'tag1' $pool->clearTags(['tag1']); $pool->getItem('tobias')->isHit(); // false $pool->getItem('aaron')->isHit(); // true
Think of a hierarchy like a file system. If you remove a folder "Foo", all items and folders in "Foo" will also be removed. A hierarchical cache key must start with a pipe ("|").
$pool->hasItem('|users|4711|followers|12|likes'); // True $pool->deleteItem('|users|4711|followers'); $pool->hasItem('|users|4711|followers|12|likes'); // False
Namespace can be used to separate the storage of different systems in the cache. This allows different sections to be cleared on an individual level, while also preventing overlapping keys.
$pool = new ArrayCachePool(); $namespaceFoo = new NamespacedCachePool($pool, 'foo'); $item = $namespaceFoo->getItem('key')->set('value'); $namespaceFoo->save($item); $namespaceBar = new NamespacedCachePool($pool, 'bar'); $namespaceBar->hasItem('key'); // False $item = $namespaceBar->getItem('key')->set('value'); $namespaceBar->save($item); $namespaceBar->hasItem('key'); // True $namespaceFoo->deleteItem('key'); $namespaceFoo->hasItem('key'); // False $namespaceBar->hasItem('key'); // True
The AdapterBundle is used to configure and register a PSR-6 cache pool as a Symfony service. The CacheBundle is used to integrate any PSR-6 cache service with the framework. It supports session cache, doctrine cache, validation cache and many more.
We would LOVE to see integration with Zend, Laravel, Yii, Cake, and even Code Igniter. If you would like to contribute, we would love to see your code.
Excluding our adapters, we have the following packages
|Cache||Base Cache Repository. Contains all adapters.|
|AdapterBundle||Bundle to register adapters to services.|
|CacheBundle||Bundle to integrate any PSR-6 service with the
|Doctrine bride||A bridge from PSR-6 to DoctrineCache|
|Hierarchical cache||A trait and interface to support cache hierachy|
|Integration tests||Used to verify any PSR-6 implementation|
|Namespaced cache||Pool to support a namespace|
|Session handler||Implementation of
|Taggable cache||Traits and interfaces to support cache tagging|