https://github.com/bpolaszek/cache
https://github.com/bpolaszek/cache
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bpolaszek/cache
- Owner: bpolaszek
- License: mit
- Created: 2020-04-15T14:16:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-20T08:39:01.000Z (over 5 years ago)
- Last Synced: 2025-01-10T09:59:28.590Z (about 1 year ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/bentools/cache)
[](https://packagist.org/packages/bentools/cache)
[](https://travis-ci.org/bpolaszek/cache)
[](https://coveralls.io/github/bpolaszek/cache?branch=master)
[](https://scrutinizer-ci.com/g/bpolaszek/cache)
[](https://packagist.org/packages/bentools/cache)
# bentools/cache
## Usage
### Cache Fallback
If calling a cache method throws an exception, it will fall back to the other cache pool.
```php
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:
```php
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.