Skip to content
SoloPHPPublic

About

PSR-16 cache for PHP with file and Redis adapters: atomic file writes, isolated Redis namespaces, typed values where a cached false or null is a hit, batches in one round trip, and a choice between throwing and falling back when storage fails.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Solo Cache

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.

About

PSR-16 cache for PHP with file and Redis adapters: atomic file writes, isolated Redis namespaces, typed values where a cached false or null is a hit, batches in one round trip, and a choice between throwing and falling back when storage fails.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages