bentools / cache
PSR-6 and PSR-16 Cache Adapters.
Installs: 2 562
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- psr/simple-cache: ^1.0
Requires (Dev)
- cache/array-adapter: ^1.0
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: ~5.0|~6.0|~7.0
- squizlabs/php_codesniffer: ^3.5
- symfony/var-dumper: ~3.0|~4.0|~5.0
This package is auto-updated.
Last update: 2024-12-20 19:06:02 UTC
README
bentools/cache
Usage
Cache Fallback
If calling a cache method throws an exception, it will fall back to the other cache pool.
use BenTools\Cache\Fallback\CacheFallback; use Cache\Adapter\Memcache\MemcacheCachePool; use Cache\Adapter\Redis\RedisCachePool; $main = new RedisCachePool(new Redis()); $default = new MemcacheCachePool(new Memcache()); $cache = new CacheFallback($main, $default); $cache->get('foo'); // if $main->get('foo') throws an exception, will call $default->get('foo')
You can use as many cache pools as you want, so that a failing cache falls back to the next healthy one:
use BenTools\Cache\Fallback\CacheFallback; use Cache\Adapter\Memcache\MemcacheCachePool; use Cache\Adapter\Redis\RedisCachePool; use Cache\Adapter\PHPArray\ArrayCachePool; $redis = new RedisCachePool(new Redis()); $memcache = new MemcacheCachePool(new Memcache()); $arrayCache = new ArrayCachePool(); $cache = new CacheFallback($redis, $memcache, $arrayCache); $cache->get('foo');
Installation
composer require bentools/cache
Tests
./vendor/bin/phpunit
License
MIT.