PHP code example of perf / caching

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

    

perf / caching example snippets




use perf\Caching\CacheClient;
use perf\Caching\Storage\FileSystemCachingStorage;
use perf\Caching\Storage\MemcachedCachingStorage;
use perf\Caching\Storage\NullCachingStorage;
use perf\Caching\Storage\VolatileCachingStorage;

// Memcached
$storage = MemcachedCachingStorage::createFromCredentials('1.2.3.4', 123);
$cache   = CacheClient::createWithStorage($storage);

// Volatile storage
$storage = new VolatileCachingStorage();
$cache   = CacheClient::createWithStorage($storage);

// File-system storage
$storage = new FileSystemCachingStorage('/tmp/cache');
$cache   = CacheClient::createWithStorage($storage);

// Null storage (caches nothing)
$storage = new NullCachingStorage();
$cache   = CacheClient::createWithStorage($storage);



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

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

// ...

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