PHP code example of mbretter / stk-cache

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

    

mbretter / stk-cache example snippets


$memcached = new Memcached();
$memcached->addServer("127.0.0.1", 11211, 50]);
$pool = new Cache\Pool\Memcached($memcached);

$cache = new Cache\Cache($pool);

$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);

$pool = new Cache\Pool\Blackhole();
$cache = new Cache\Cache($pool);

$pool = new Cache\Pool\Memory();
$cache = new Cache\Cache($pool);

$pool = new Cache\Pool\APCu();
$cache = new Cache\Cache($pool);

$val = $cache->getSet('mykey', function() {
    // ... do some expensive calculations
    return $val;
});

$groupkey = 'mygroup';

$cache->setGrouped($groupkey, 'key1', $val1);
$cache->setGrouped($groupkey, 'key2', $val2);
$cache->setGrouped($groupkey, 'key-' . uniqid(), $val2);

$cache->delete($groupkey); // invalidates key1, key2, key-xxxx

$val = $cache->getGrouped($groupkey, 'key1'); // $val is null