PHP code example of onoi / cache
1. Go to this page and download the library: Download onoi/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/ */
onoi / cache example snippets
use Onoi\Cache\Cache;
class Foo {
private $cache = null;
public function __constructor( Cache $cache ) {
$this->cache = $cache;
}
public function doSomething( $id ) {
if ( $this->cache->contains( $id ) ) {
// do something
}
}
}
$cacheFactory = new CacheFactory();
$instance = new Foo( $cacheFactory->newFixedInMemoryLruCache( 500 ) );
$instance->doSomething( 'bar' );
or
$compositeCache = $cacheFactory->newCompositeCache( array(
$cacheFactory->newFixedInMemoryLruCache( 500 ),
$cacheFactory->newDoctrineCache( new \Doctrine\Common\Cache\RedisCache() ),
$cacheFactory->newMediaWikiCache( new \SqlBagOStuf() )
) );
$instance = new Foo( $compositeCache );
$instance->doSomething( 'bar' );