A collection of caching classes with a common interface (currently file cache and memcached are supported).
Via Composer
$ composer require vakata/cache
// create an instance (with file based cache)
// caches will be stored in the dir specified by the first argument
$cache = new \vakata\cache\Filecache(__DIR__ . '/cache');
// to use Memcached instead simply create a memcached instance:
// $cache = new \vakata\cache\Memcache(); // by default connects to 127.0.0.1
// simple get / set
$cache->set('key', 'value'); // key is stored and "value" is returned
$cache->get('key'); // "value"
// using prepare ensures that a single client updates the cache at any given moment
$cache->prepare('long-running-operation');
$data = long_running_operation();
$cache->set('long-running-operation', $data);
// there is a special getSet method which gets the current key value and if it does not exist - invokes a callable, stores the result and returns it:
$cache->getSet('some-key', function () {
return some_long_running_operation();
});
Read more in the API docs
$ composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email github@vakata.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.