PHP code example of beste / in-memory-cache
1. Go to this page and download the library: Download beste/in-memory-cache library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beste / in-memory-cache example snippets
use Beste\Cache\InMemoryCache;
$cache = new InMemoryCache();
$item = $cache->getItem('key');
assert($item->isHit() === false);
assert($item->get() === null);
$item->set('value');
$cache->save($item);
// Later...
$item = $cache->getItem('key');
assert($item->isHit() === true);
assert($item->get() === 'value');
use Beste\Clock\FrozenClock;
use Beste\Cache\InMemoryCache;
$clock = FrozenClock::fromUTC()
$cache = new InMemoryCache();
$item = $cache->getItem('key');
$item->set('value')->expiresAfter(new DateInterval('PT5M'));
$cache->save($item);
$clock->setTo($clock->now()->add(new DateInterval('PT2M')));
assert($cache->getItem('key')->isHit() === true);
$clock->setTo($clock->now()->add(new DateInterval('PT5M')));
assert($cache->getItem('key')->isHit() === false);