PHP code example of comporu / cache

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

    

comporu / cache example snippets

 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\NotCache;

$cache = new Cache(new NotCache());

$cache->set('key', 'myKeyValue', 3600);

// later ...

echo $cache->get('key');

 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Apcu;

$adapter = new Apcu();
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);

 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\File;

$cacheDir = '/tmp';
$adapter = new File($cacheDir);
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);

 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Memcache;

$adapter = new Memcache();
$cache = new Cache($adapter);

 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Memcache;    
use \Memcache as Backend

$backend = new Backend();
// configure it here

$cache = new Cache(new Memcache($backend));
 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Memory;

$adapter = new Memory();
$adapter->setOption('ttl', 3600);
$adapter->setOption('limit', 200);
$cache = new Cache($adapter);

 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Mongo;

$client = new MongoClient($dsn);
$database = $client->selectDatabase($dbname);

$adapter = new Mongo($database);
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);

 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Mongo;

$client = new MongoClient($dsn);
$database = $client->selectDatabase($dbName);
$collection = $database->selectCollection($collectionName);

$adapter = new Mongo($collection);
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);

 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Mysqli;

$adapter = new Mysqli();
$adapter->setOption('ttl', 3600);
$cache = new Cache($adapter);

 php

    
use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Mysqli;    
use \mysqli as Backend

$backend = new Backend();
// configure it here

$cache = new Cache(new Mysqli($backend));
 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Predis;

$adapter = new Predis();
$cache = new Cache($adapter);

 php


use Desarrolla2\Cache\Cache;
use Desarrolla2\Cache\Adapter\Predis;
use Predis\Client as Backend

$adapter = new Predis(new Backend($options));
$cache = new Cache($adapter);