PHP code example of bentools / cache

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

    

bentools / cache example snippets


use BenTools\Cache\Fallback\CacheFallback;
use Cache\Adapter\Memcache\MemcacheCachePool;
use Cache\Adapter\Redis\RedisCachePool;

$main = new RedisCachePool(new Redis());
$default = new MemcacheCachePool(new Memcache());
$cache = new CacheFallback($main, $default);
$cache->get('foo'); // if $main->get('foo') throws an exception, will call $default->get('foo')

use BenTools\Cache\Fallback\CacheFallback;
use Cache\Adapter\Memcache\MemcacheCachePool;
use Cache\Adapter\Redis\RedisCachePool;
use Cache\Adapter\PHPArray\ArrayCachePool;

$redis = new RedisCachePool(new Redis());
$memcache = new MemcacheCachePool(new Memcache());
$arrayCache = new ArrayCachePool();
$cache = new CacheFallback($redis, $memcache, $arrayCache);
$cache->get('foo');