angrybytes / cache
This package is abandoned and no longer maintained.
No replacement package was suggested.
Cache store with support for various adapters
1.0.3
2014-09-05 10:16 UTC
Requires (Dev)
- phpunit/phpunit: ~3.7.0
This package is not auto-updated.
Last update: 2020-08-04 14:59:56 UTC
README
This package is no longer maintained!
This is a simple cache store with support for a variety of backends. A file and memcached backend are included.
Installation
Installation through Composer at Packagist
Usage
Usage is simple:
<?php // Instantiate $adapter = new AngryBytes\Cache\Adapter\Memcached; $adapter->addServer('localhost', 11211); $cache = new AngryBytes\Cache\Cache($adapter); // Save $cache->save($yourExpensiveData, 'cache-key'); // Load $data = $cache->load('cache-key'); // Delete $data = $cache->delete('cache-key');
Result checking
There is a special return type AngryBytes\Cache\ResultNotFound
that signifies the
result can not be retrieved:
<?php // Load $data = $cache->load('cache-key'); // Check if ($data instanceof AngryBytes\Cache\ResultNotFound) { $yourExpensiveData = yourExpensiveMethod(); // Save $cache->save($yourExpensiveData, 'cache-key'); }
ID Prefixing
If you need to support more than one cache store on the same backend you can add a prefix for all id's:
<?php // Two stores with same adapter but different prefix: $cache1 = new AngryBytes\Cache\Cache($adapter); $cache1->setIdPrefix('foo'); $cache2 = new AngryBytes\Cache\Cache($adapter); $cache2->setIdPrefix('foo');
You can also add more than one prefix, which can be handy for key cleaning:
<?php $cache = new AngryBytes\Cache\Cache($adapter); $cache->addIdPrefix('foo'); $cache->addIdPrefix('bar');