Search by

solophp / cache

Vitaliy Olos

PSR-16 cache for PHP with atomic file and Redis adapters, typed values and an explicit failure policy

Package info

github.com/SoloPHP/Cache

pkg:composer/solophp/cache

Statistics

Installs: 51

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.1 2026-11-02 19:25 UTC

This package is auto-updated.

Last update: 2026-11-03 07:01:05 UTC


README

Latest Version on Packagist PHP Version License

PSR-16 cache for PHP with file and Redis adapters. File writes publish atomically through a temporary file and rename(); a Redis pool lives under its own key prefix and sends each batch in one round trip. Values keep their types, so a cached false or null is a hit, and ErrorMode decides whether a failing backend throws or turns into a miss.

Installation

composer require solophp/cache

Requires PHP 8.3+. The Redis adapter also needs the redis extension.

Example

use Solo\Cache\Adapter\FileAdapter;
use Solo\Cache\Adapter\RedisAdapter;

$cache = new FileAdapter(__DIR__ . '/var/cache/catalog');
$cache->set('product.42', ['name' => 'Desk'], 3600);
$product = $cache->get('product.42'); // ['name' => 'Desk']

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

$cache = new RedisAdapter($redis, prefix: 'catalog:');
$cache->setMultiple(['product.42' => 'Desk', 'product.43' => 'Chair'], 600);
$cache->getMultiple(['product.42', 'product.44'], 'missing');
// ['product.42' => 'Desk', 'product.44' => 'missing']

Both adapters implement Psr\SimpleCache\CacheInterface, so application code type-hints the interface and the adapter is chosen where services are wired. Keys use ASCII letters, digits, _, . and -. Reads never delete files, so schedule FileAdapter::gc() to reclaim the space of expired entries.

Documentation

Full Documentation

License

MIT. See LICENSE.