PHP code example of angrybytes / cache

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

    

angrybytes / cache example snippets




// Instantiate
$adapter = new AngryBytes\Cache\Adapter\Memcached;
$adapter->addServer('localhost', 11211);

$cache = new AngryBytes\Cache\Cache($adapter);

// Save
$cache->save($yourExpensiveData, 'cache-key');

// Load
$data = $cache->load('cache-key');

// Delete
$data = $cache->delete('cache-key');



// Load
$data = $cache->load('cache-key');

// Check
if ($data instanceof AngryBytes\Cache\ResultNotFound) {
    $yourExpensiveData = yourExpensiveMethod();

    // Save
    $cache->save($yourExpensiveData, 'cache-key');
}



// Two stores with same adapter but different prefix:

$cache1 = new AngryBytes\Cache\Cache($adapter);
$cache1->setIdPrefix('foo');

$cache2 = new AngryBytes\Cache\Cache($adapter);
$cache2->setIdPrefix('foo');



$cache = new AngryBytes\Cache\Cache($adapter);
$cache->addIdPrefix('foo');
$cache->addIdPrefix('bar');