phpFastCachePHP 緩存庫
phpFastCache 是一個開源的 PHP 緩存庫,只提供一個簡單的 PHP 文件,可方便集成到已有項目,支持多種緩存方法,包括:apc, memcache, memcached, wincache, files, pdo and mpdo。可通過簡單的 API 來定義緩存的有效時間。
示例代碼:
<?php
// In your config file
include("php_fast_cache.php");
// This is Optional Config only. You can skip these lines.
// phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "pdo", "mpdo" and "xcache"
// You don't need to change your code when you change your caching system. Or simple keep it auto
phpFastCache::$storage = "auto";
// End Optionals
// In your Class, Functions, PHP Pages
// try to get from Cache first.
$products = phpFastCache::get("products_page");
if($products == null) {
$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
// set products in to cache in 600 seconds = 10 minutes
phpFastCache::set("products_page",$products,600);
}
foreach($products as $product) {
// Output Your Contents HERE
}
?>
評論
圖片
表情
