PHP code example of beryllium / cache

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

    

beryllium / cache example snippets


$client = new Beryllium\Cache\Client\FilecacheClient(__DIR__ . '/cache/');
$cache  = new Beryllium\Cache\Cache($client);

// One Hour Time-To-Live
$cache->setTtl(3600);

// Prefix Filenames with extra information, such as 'www-'
$cache->setPrefix('www-');

$cache->set('latest-news-items', $newsArray);

$cache->get('latest-news-items', []);

$client = new Beryllium\Cache\Client\ApcuClient();
$cache  = new Beryllium\Cache\Cache($client);
$cache->setPrefix('apcu-cache:');

$path   = __DIR__ . '/../../somewhere/over/the/rainbow';
$client = new Beryllium\Cache\Client\FilecacheClient($path);
$cache  = new Beryllium\Cache\Cache($client);
$cache->setPrefix('what-a-wonderful-world-');

$client = new Beryllium\Cache\Client\MemcachedClient();
$client->addServer('localhost', 11211);
$cache = new Beryllium\Cache\Cache($client);

$memcached = new \Memcached();
$memcached->addServer('localhost', 11211);

$client = new Beryllium\Cache\Client\MemcachedClient($memcached);
$cache  = new Beryllium\Cache\Cache($client);

$memcached = new \Memcached();
$verifier  = new \Beryllium\Cache\Client\ServerVerifier\MemcacheServerVerifier();
$client    = new Beryllium\Cache\Client\MemcachedClient(
    $memcached,
    $verifier
);

$client->addServer('localhost', 11211);
$cache = new Beryllium\Cache\Cache($client);

$client = new Beryllium\Cache\Client\MemoryClient();
$cache  = new Beryllium\Cache\Cache($client);

$client = new Beryllium\Cache\Client\ApcuClient();
$ignore = new Beryllium\Cache\Wrapper\IgnoreThrowablesWrapper($client);
$cache  = new Beryllium\Cache\Cache($ignore);
$cache->setPrefix('apcu-cache:');

$client1 = new Beryllium\Cache\Client\MemoryClient();
$client2 = new Beryllium\Cache\Client\ApcuClient();
$client3 = new Beryllium\Cache\Client\MemcachedClient();
$client4 = new Beryllium\Cache\Client\FilecacheClient('/mnt/tmp/cache');
$cascade = new Beryllium\Cache\Wrapper\CascadeWrapper(
    $client1,
    $client2,
    $client3,
    $client4
);

$client3->addServer('localhost', 11211);

$cache = new Beryllium\Cache\Cache($cascade);