PHP code example of psx / cache

1. Go to this page and download the library: Download psx/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/ */

    

psx / cache example snippets




$pool = new PSX\Cache\Pool(new Doctrine\Common\Cache\FilesystemCache());
$item = $pool->getItem('foo');

if (!$item->isHit()) {
    $value = doComplexTask();

    $item->set($value);
    $item->expiresAfter(3600);

    $pool->save($item);
} else {
    $value = $item->get();
}



$cache = new PSX\Cache\SimpleCache(new Doctrine\Common\Cache\FilesystemCache());
$value = $cache->get('foo');

if ($value === null) {
    $value = doComplexTask();

    $cache->set('foo', $value, 3600);
}