initphp/cache is a PSR-16 cache library
with interchangeable handlers. You configure a handler once through the
Cache::create() factory and then use the standard PSR-16 API everywhere.
- Getting started — install, the factory, the read-through pattern.
- Configuration & options — every option of every handler.
- PSR-16 behaviour & the handler API — keys, TTLs, bulk methods and the counter contract.
- Handlers
- Exceptions
use InitPHP\Cache\Cache;
use InitPHP\Cache\Handler\File;
$cache = Cache::create(File::class, ['path' => __DIR__ . '/var/cache']);
$cache->set('key', 'value', 300); // store for 5 minutes
$cache->get('key'); // "value"
$cache->get('missing', 'default');// "default"
$cache->has('key'); // true
$cache->delete('key'); // trueEvery handler implements InitPHP\Cache\CacheInterface, which extends
Psr\SimpleCache\CacheInterface. Code that depends on the PSR interface works
with any handler unchanged.