PSR-16 compliant cache that stores values as PHP files, suitable for OPcaching.
composer require typhoon/opcache
use Typhoon\OPcache\TyphoonOPcache;
$cache = new TyphoonOPcache('path/to/cache/dir');
$cache->set('key', $value);
assert($cache->get('key') == $value);
According to PSR-16:
If a calling library asks for an item to be saved but does not specify an expiration time, or specifies a null expiration time or TTL, an Implementing Library MAY use a configured default duration.
Here's how you can configure default TTL:
use Typhoon\OPcache\TyphoonOPcache;
$cache = new TyphoonOPcache(
directory: 'path/to/cache/dir',
defaultTtl: new DateInterval('T1M'),
);
use Typhoon\OPcache\TyphoonOPcache;
$cache = new TyphoonOPcache('path/to/cache/dir');
$cache->prune();