// boilerplate code example with Memcached, but any // MatthiasMullie\Scrapbook\KeyValueStore adapter will work $client = new \Memcached(); $client->addServer('localhost', 11211); $cache = new \MatthiasMullie\Scrapbook\Adapters\Memcached($client); // create Simplecache object from cache engine $simplecache = new \MatthiasMullie\Scrapbook\Psr16\SimpleCache($cache); // get value from cache $value = $simplecache->get('key'); // ... or store a new value to cache $simplecache->set('key', 'updated-value');
PSR-16 (a PHP-FIG standard) is a second PHP-FIG cache standard. It’s a driver model just like KeyValueStore, and it works very much in the same way.
It doesn’t let you do too many operations. If
delete (and their
*multi counterparts) and
delete is all you need, you’re probably better off
using this (or psr/cache) as this interface is also supported by other cache
This interface bridges the gap between KeyValueStore based adapters & features, and PSR-16: any of the Scrapbook tools are accessible in a PSR-16 compatible manner.
Fetch a value from the cache.
set($key, $value, $ttl): bool
Persist data in the cache, uniquely referenced by a key with an optional expiration TTL time.
Delete an item from the cache by its unique key.
Wipe clean the entire cache's keys.
Obtain multiple cache items by their unique keys.
setMultiple($items, $ttl): bool
Persisting a set of key => value pairs in the cache, with an optional TTL.
Delete multiple cache items in a single operation.
Identify if an item is in the cache.