PHP code example of corneltek / universal-cache

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

    

corneltek / universal-cache example snippets


use UniversalCache\ApcuCache;
use UniversalCache\FileSystemCache;
use UniversalCache\UniversalCache;

$cache = new UniversalCache([
    new ArrayCache, // Fetch cache without serialization if there is a request-wide cache exists.
    new ApcuCache('app_', 60), // Faster then file system cache.
    new FileSystemCache(__DIR__ . '/cache'),
]);
$cache->set('key', 'value');
$value = $cache->get('key');

$cache = new UniversalCache\ApcuCache('app_', 3600); // 3600 = expiry time
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

$cache = new UniversalCache\ArrayCache;
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

$cache = new UniversalCache\MemcacheCache([
    'servers' => [['localhost', 123123], ['server2',123123] ]
]);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

$cache = new UniversalCache\RedisCache($redisConnection);
$cache->set($name,$val);
$val = $cache->get($name);
$cache->remove($name);

$serializer = new SerializerKit\JsonSerializer();
$cache = new UniversalCache\FileSystemCache(__DIR__ . '/cache', [
    'expiry' => 30,
    'serializer' => $serializer,
]);