PSR-16 simple-cache

Fork PSR-16 simple-cache on GitHub
// 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 get, set, 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 libraries.

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.


get($key): mixed

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(): void

Delete an item from the cache by its unique key.

clear(): void

Wipe clean the entire cache's keys.

getMultiple($keys): mixed[]

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.

deleteMultiple($keys): bool

Delete multiple cache items in a single operation.

has($key): bool

Identify if an item is in the cache.

psr/simple-cache is a PHP-FIG (Framework Interop Group) standard for a driver model cache implementation. It's a relatively simple & straightforward driver model interface, very similar to KeyValueStore.


Project links



composer require matthiasmullie/scrapbook