solophp / cache
PSR-16 cache for PHP with atomic file and Redis adapters, typed values and an explicit failure policy
Requires
- php: ^8.3
- psr/simple-cache: ^3.0
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^4.0
Suggests
- ext-redis: Required for Redis cache adapter
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-03 07:01:05 UTC
README
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
- Getting Started
- File Cache
- Redis Cache
- Expiration
- Batches
- Failure Modes
- Application Wiring
- API Reference
- Behavior in Detail
- Upgrading from 1.x
- Changelog
License
MIT. See LICENSE.