PHP緩存管理,HybridCache 0.8.5 發布
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);</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!