PHP >= 8.1
composer require phant/cache
Phant Cache implement the PSR-16 SimpleCache interface :
Psr\SimpleCache\CacheInterface
Store cache in file.
use Phant\Cache\File as CacheFile;
$cache = new CacheFile('path/cache/', 'my-cache-container', CacheFile::TTL_HOUR);
Store cache in runtime memory.
use Phant\Cache\Runtime as CacheRuntime;
$cache = new CacheRuntime();
$val = $cache->getOrSet(
'my-key',
function () {
return 'my-val';
},
$cache::TTL_HOUR
);
if ($cache->has('my-key')) {
}
$cache->set('my-key', 'my-val', $cache::TTL_HOUR);
$val = $cache->get('my-key');
$cache->delete('my-key');
$cache->setMultiple([
'my-key-1' => 'val-1',
'my-key-2' => 'val-2',
'my-key-3' => 'val-3',
], $cache::TTL_HOUR);
foreach ($cache->getMultiple([
'my-key-1',
'my-key-2',
'my-key-3',
]) as $val) {
}
$cache->deleteMultiple([
'my-key-1',
'my-key-2',
'my-key-3',
]);
$cache->clear();