1. Go to this page and download the library: Download romeoz/rock-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/ */
romeoz / rock-cache example snippets
$config = [
'hashKey' => CacheInterface::HASH_MD5, // Default: HASH_MD5
'serializer' => CacheInterface::SERIALIZE_JSON // Default: SERIALIZE_PHP - php serializator
];
$memcached = new \rock\cache\Memcached($config); // or \rock\cache\versioning\Memcached for approach versioning
$tags = ['tag_1', 'tag_2'];
$value = ['foo', 'bar'];
$expire = 0; // If use expire "0", then time to live infinitely
$memcached->set('key_1', $value, $expire, $tags);
// automatic unserialization
$memcached->get('key_1'); // result: ['foo', 'bar'];
$memcached->flush(); // Invalidate all items in the cache
$memcached = new \rock\cache\Memcached
$value = $memcached->get('key_1');
if ($value !== false) {
return $value;
}
if ($memcached->lock('key_1')) {
// the query to DBMS or other...
$memcached->set('key_1', 'foo');
$memcached->unlock('key_1');
}