1. Go to this page and download the library: Download exos/hybridcache 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/ */
exos / hybridcache example snippets
// vendor/autoload.php');
use Hybrid\Cache;
// Use other name for no conflicts with Memcache Class
use Hybrid\Storages\Memcache as MemcacheStorage;
// add a MediaStorage to the Cache class:
Cache::addStorageMedia( new MemcacheStorage('localhost') );
// create a cache instance, with an identifier (can be a lot of values):
$cache = Cache::create(__FILE__, 'list top users');
// check if cache exists and is aviable
$data = $cache->getCacheOr(true, function ($cache) {
// make your heavy processing.... (saving the result in a variable)
return $result;
});
// Or...
if ($data = $cache->getCache(true)) {
// dump cached data
echo $data;
// stop the script (or the method, ect)
exit(0);
} else {
// set the cache status as "saving" (to avoid duplicating entries)
$cache->setStatusSaving();
}
// make your heavy processing.... (saving the result in a variable)
// dump the result
echo $result;
// cache the result
$cache->save($result);
use Hybrid\Storages\Redis as RedisStorage;
// Define Redis server for write only (master)
Cache::addStorageMedia( new RedisStorage('10.1.30.1'), Cache::FOR_WRITE );
// Define the rest of servers for read only
Cache::addStorageMedia( new RedisStorage('10.1.30.2'), Cache::FOR_READ );
Cache::addStorageMedia( new RedisStorage('10.1.30.3'), Cache::FOR_READ );
Cache::addStorageMedia( new RedisStorage('10.1.30.4'), Cache::FOR_READ );
Cache::addStorageMedia( new RedisStorage('10.1.30.5'), Cache::FOR_READ );
use Hybrid\Storages\Memcache as MemcacheStorage;
Cache::addStorageMedia( new MemcacheStorage('10.1.30.1') );
Cache::addStorageMedia( new MemcacheStorage('10.1.30.2') );
Cache::addStorageMedia( new MemcacheStorage('10.1.30.3') );
Cache::addStorageMedia( new MemcacheStorage('10.1.30.4') );
Cache::addStorageMedia( new MemcacheStorage('10.1.30.5') );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.