Slim and full compatible PSR-16 cache library for PHP
Install via the composer utility.
composer require "phoole/cache"or add the following lines to your composer.json
{
"require": {
"phoole/cache": "1.1.*"
}
}Fully PSR-16 compliant.
Support all serializable PHP data types.
Extra features:
Stampede Protection: Whenever ONE cached object's lifetime is less than a configurable
stampedeGaptime in seconds (60s default), by a configurablestampedePercent(5% default) percentage, it will be considered stale. It may then trigger generating new cache depend on your decision. This feature is quite useful for reducing a single hot item stampede situation.// overwrite stampede defaults$cache = newCache($fileAdatpor, [ 'stampedeGap' => 120, // 120second'stampedePercent' => 2// 2% ]);
Distributed expiration: By setting
distributedPercent(5% default) to a reasonable percentage, system will store each cache item with its TTL(time to live) a small random fluctuation. This will help avoiding large amount of items expired at the same time.$cache = newCache($fileAdaptor, [ 'distributedPercent' => 3, // 3%, default is 5% ]);
CacheAwareInterfaceandCacheAwareTrait
Simple usage
usePhoole\Cache\Cache; // using default adaptor and default settings$cache = newCache(); // get with default value 'phoole'$name = $cache->get('name', 'phoole'); // set cache$cache->set('name', 'wow');
Specify the adaptor
usePhoole\Cache\Cache; usePhoole\Cache\Adaptor\FileAdaptor; // use file adaptor and specific cache directory $cache = newCache(newFileAdaptor('/tmp/cache');
Use with dependency injection
usePhoole\Cache\Cache; usePhoole\Di\Container; usePhoole\Config\Config; // config cache in the container$container = newContainer(newConfig( 'di.service' => [ 'cache' => Cache::class ], )); // get from container$cache = $container->get('cache'); // or static FACADE way$cache = Container::cache();
$ composer testPHP >= 7.2.0
phoole/base 1.*
