PHP code example of overdesign / psr-cache

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

    

overdesign / psr-cache example snippets



use Overdesign\PsrCache\FileCacheDriver;

$cacheDir = __DIR__ . '/cache';

$cache = new FileCacheDriver($cacheDir);

$item = $cache->getItem('myItem');

if ($item->isHit()) {
    echo 'Item found in cache';
    var_dump($item->get());
} else {
    $item->set('my data');
    $item->expiresAfter(120); // Expire in 2 min
    
    $cache->save($item);
}