PSR-16 simplecache

Fork PSR-16 simplecache 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/simplecache is an attempt to standardize how cache is implemented across frameworks & libraries in the PHP landscape.

It’s a relatively simple & straightforward driver model interface. It’s very similar to KeyValueStore, but supports fewer features (e.g. CAS is missing).

This project bridges the gap between KeyValueStore based adapters & extras, 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.

increment($key, $step): int|bool

Increment a value atomically in the cache by its step value, which defaults to 1.

decrement($key, $step): int|bool

Decrement a value atomically in the cache by its step value, which defaults to 1.

psr/simplecache 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