PHP缓存管理,HybridCache 0.8.5 发布

jopen 11年前

HybridCache是一个PHP包,用于管理包含抽象数据存储的缓存。在它内部,其利用一个键/值字典作为存储介质,但也可以通过适配器扩展其存储引擎如:SQLite,可以同时使用多种存储引擎。当前支持:Memcache 和 Redis。

这次发布实现了"Object Pool Patterngit",修复了"cancel"方法,为"implement object pool".添加"reset"方法。

示例:

<?php    // require init.php for autoload classes  require('lib/init.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    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);