herroffizier / limcache
Non-persistent cache manager with LRU and MRU algorithms
dev-master
2015-02-20 12:14 UTC
Requires
- php: >=5.4
Requires (Dev)
- phing/phing: dev-master
- phpunit/phpunit: ~3
- squizlabs/php_codesniffer: dev-master
This package is not auto-updated.
Last update: 2024-12-21 18:29:56 UTC
README
Limcache is a small non-persistent cache manager that supports LRU and MRU replacement algorithms. Also it has optional Judy support.
Requirements
- PHP >= 5.4
- Judy (optional)
Installation
You can install Limcache via Composer:
composer require herroffizier/limcache:dev-master
Usage
At first, choose replacement algorithm:
// Use LRU: $strategy = new \Limcache\strategy\LRU(100); // 100 is max item count in cache // Or MRU: $strategy = new \Limcache\strategy\MRU(100);
After that you can create cache:
$cache = new \Limcache\Cache($strategy);
Since \Limcache\Cache
implements \ArrayAccess
and \Countable
interfaces you can use it as array in most cases:
// Save item in cache: $cache['key1'] = 'somedata'; // Get item value: $cache['key1']; // Try to get non-existent item: $cache['key2']; // will return null // Do some ordinary things: count($cache); isset($cache['key1']); unset($cache['key1']);
In addition cache object has few useful methods which may help to determine cache efficiency:
// Get cache hits: $cache->getHits(); // Get cache misses: $cache->getMisses();