A caching library for PHP, implementing both PSR-6 and PSR-16., (*1)
PSR-6: Cache Interface PSR-16: Simple Cache, (*2)
This library is a storage abstraction layer, which can be used as a cache client., (*3)
It provides CRUD access to several storage backends., (*4)
This library is a storage abstraction layer, which can be used as a cache client., (*6)
It provides CRUD access to several storage backends., (*7)
You can use this layer to store and read information using these backends:, (*8)
This library is available as composer package:, (*9)
composer require ceus-media/cache
Of cource, you will need to use composer autoloader:, (*10)
<?php require_once 'vendor/autoload.php';
use CeusMedia\Cache\Factory as CacheFactory; $cache = CacheFactory::createStorage( 'Folder', __DIR__.'/cache' );
This would create a new folder cache
in the current working directory, if allowed., (*11)
$cache->set( 'aRandomDigit', rand( 0, 9 ) );
Within the folder there would be file aRandomDigit
, holding a digit between 0 and 9., (*12)
You can later read this information, again:, (*13)
$digit = $cache->get( 'aRandomDigit' ); if( NULL !== $digit ){ // cache hit } else { // cache miss }
As you can see, the result is NULL
, if the requested information is not cached (cache miss)., (*14)
You can check if an information is cached:, (*15)
if( $cache->has( 'aRandomDigit' ){ // cache hit } else { // cache miss }
As defined in PHP-Figs PSR-6 there is a cache pool with items., (*16)
use CeusMedia\Cache\CachePoolFactory; $pool = CachePoolFactory::createPool( 'Folder', __DIR__.'/cache' );
This would create a new folder cache
in the current working directory, if allowed., (*17)
// get an existing or empty item $item = $pool->getItem( 'datetime' ); // set the new (or first) value $item->set( date( DATE_ATOM ) ); // persist item in pool $pool->save( $item );
Within the folder there would be file datetime
, holding a timestamp., (*18)
You can later read this information, again:, (*19)
$item = $pool->getItem( 'datetime' ); if( $item->isHit() ){ $date = $item->get(); // ... } else { // ... }
In the past, this library was called Ceus Media Modules: Storage Engine Abstraction, in short CMM_SEA., (*20)
We used it for caching, mostly., (*21)
During migration via different VCSs and due to corporate wide product renaming, it became CeusMedia/Cache on GitHub., (*22)
Since a migration to implement PHP-Figs cache releated PSRs, there are now two ways to use this library., (*23)
Slow storages have been removed to keep an eye on performance., (*24)
Connector Factory, (*25)
Replace the current resource strings, used on connecting a cache backend, by connector objects. For each backend there will be a connector class. A factory will ease the creation of these connectors., (*26)
Layered Caches, (*27)
A cache client instance can have several backends, which are used in a defined order. This way, a slow cache backend (like a database or file based cache) can be wrapped by a faster cache backend (like a local memcache server). There are many interesting use cases., (*28)
Flattening Strategy, (*29)
Since some cache backends cannot store structured data, a flattening strategy is needed. At the moment, each backend implements its own strategy. A better way is to select a stategy., (*30)
Cache Manager, (*31)
Several cache client instances can be registered on a cache manager, which is a single resource for larger projects, like an application framework. During actions within the framework, the developer can select between several caches for different purposes., (*32)
More backends, (*33)
Custom backends, (*34)
Allow to register own cache backends., (*35)