typhoon/opcache

PSR-16 compliant cache that stores values as PHP files, suitable for OPcaching.

0.2.1 2024-02-19 16:31 UTC

This package is auto-updated.

Last update: 2024-04-19 17:06:02 UTC


README

PSR-16 compliant cache that stores values as PHP files, suitable for OPcaching.

Installation

composer require typhoon/opcache

Usage

use Typhoon\OPcache\TyphoonOPcache;

$cache = new TyphoonOPcache('path/to/cache/dir');

$cache->set('key', $value);

assert($cache->get('key') == $value);

How to configure default TTL

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'),
);

How to delete stale cache items

use Typhoon\OPcache\TyphoonOPcache;

$cache = new TyphoonOPcache('path/to/cache/dir');
$cache->prune();