dev-master
9999999-dev http://github.com/digitalcreations/cacheCache interface
MIT
The Development Requires
cache memcached
Wallogit.com
2017 © Pedro Peláez
Cache interface
, (*1)
$ composer install dc/cache
Or add it to composer.json:, (*2)
"require": {
"dc/cache": "0.*",
}
$ composer install
This package suggests dc/cache-memcache, which is the only implementation at this point., (*3)
This is just an interface. You probably should install dc/cache-memcahe or write your own implementation to the interface., (*4)
When you have, you can use the interface like this:, (*5)
$cache = new \SomeImplementation();
$cache->set('foo', 'bar');
echo $cache->get('foo'); // prints bar
A common pattern is that you want a specific value from the cache, and if it is a cache miss, you want to produce it:, (*6)
echo $cache->getWithFallback('foo', function() {
return 'bar';
}); // prints bar
$cache->get('foo'); // now also prints bar
This syntax works with any callable, not just closures., (*7)
You can also use the return value to determine the validity., (*8)
$foo = $cache->getWithFallback("foo",
function($x) { return ["foo" => $x, "expires" => \DateInterval($x)]; },
function($result) { return $result["expires"]; });
Cache interface
MIT
cache memcached