PHP code example of jmf / simple-cache

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

    

jmf / simple-cache example snippets




use Jmf\Cache\CacheClient;
use Jmf\Cache\Storage\FileSystemStorage;
use Jmf\Cache\Storage\MemcachedStorage;
use Jmf\Cache\Storage\NullStorage;
use Jmf\Cache\Storage\VolatileStorage;
use Psr\Clock\ClockInterface;
use Psr\Log\LoggerInterface;

/* @var ClockInterface $clock */
/* @var LoggerInterface $logger */

// Memcached
$storage = MemcachedStorage::createFromCredentials('123.45.67.89');
$cache   = new CacheClient($storage, $clock, $logger);

// Volatile storage
$storage = new VolatileStorage();
$cache   = new CacheClient($storage, $clock, $logger);

// File-system storage
$storage = new FileSystemStorage('/tmp/cache');
$cache   = new CacheClient($storage, $clock, $logger);

// Null storage (caches nothing)
$storage = new NullStorage();
$cache   = new CacheClient($storage, $clock, $logger);



$objectToStore = new \stdClass();
$objectToStore->bar = 'baz';

$cache->set('foo', $objectToStore);

// ...

$object = $cache->get('foo');