quillstack/cache

A simple cache based on PSR-16: Common Interface for Caching Libraries.

Maintainers

Package info

github.com/quillstack/cache

Homepage

pkg:composer/quillstack/cache

Transparency log

Statistics

Installs: 125

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.6.0 2026-08-21 20:53 UTC

This package is auto-updated.

Last update: 2026-08-23 00:22:15 UTC


README

Tests Latest Version Downloads PHP Version StyleCI CodeFactor Quality Gate Coverage Maintainability Reliability Security License

A simple cache based on PSR-16: Common Interface for Caching Libraries.

Installation

composer require quillstack/cache

Usage

Two caches come with it. ArrayCache keeps entries for as long as the process runs, which is what a single request needs:

use Quillstack\Cache\ArrayCache;

$cache = new ArrayCache();
$cache->set('user.42', $user, 300);

$user = $cache->get('user.42', $default);

FileCache writes them to disk, so they outlive the request:

use Quillstack\Cache\FileCache;
use Quillstack\LocalStorage\LocalStorage;

$cache = new FileCache(new LocalStorage(), __DIR__ . '/var/cache');

How long an entry lives is given in seconds, as a DateInterval, or left out to keep it for as long as the cache does:

$cache->set('key', $value, 60);
$cache->set('key', $value, new DateInterval('PT1H'));
$cache->set('key', $value);

getMultiple(), setMultiple() and deleteMultiple() work on several keys at once, has() says whether a key is there, and clear() empties the cache.

Time

Both caches take a PSR-20 clock, which is what decides when an entry has run out. Without one they read the wall clock. FrozenClock stands still until it is moved, so a test does not have to wait:

use Quillstack\Cache\Clock\FrozenClock;

$clock = new FrozenClock();
$cache = new ArrayCache($clock);

$cache->set('key', 'value', 60);
$clock->sleep(61);

$cache->get('key'); // null

Keys

PSR-16 asks a key to hold at least one character and none of {}()/\@:. A key which does not is refused with an InvalidCacheKeyException, which is a Psr\SimpleCache\InvalidArgumentException.

Tests

composer test

Coverage needs phpdbg:

composer test:coverage

License

MIT. See LICENSE.