// phpFastCache support "apc", "memcache", "memcached", "wincache" ,"files", "sqlite" and "xcache" // You don't need to change your code when you change your caching system. Or simple keep it auto $cache = phpFastCache();
// In your Class, Functions, PHP Pages // try to get from Cache first. product_page = YOUR Identity Keyword $products = $cache->get("product_page");
if($products == null) { $products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION; // set products in to cache in 600 seconds = 10 minutes $cache->set("product_page", $products,600); }
// Output Your Contents $products HERE
提高cURL和API调用性能
<?php include("phpfastcache/phpfastcache.php");
$cache = phpFastCache("memcached");
// try to get from Cache first. $results = $cache->get("identity_keyword")
if($results == null) { $results = cURL->get("http://www.youtube.com/api/json/url/keyword/page"); // Write to Cache Save API Calls next time $cache->set("identity_keyword", $results, 3600*24); }
foreach($results as $video) { // Output Your Contents HERE }
if($html == null) { ob_start(); /* ALL OF YOUR CODE GO HERE RENDER YOUR PAGE, DB QUERY, WHATEVER */
// GET HTML WEBPAGE $html = ob_get_contents(); // Save to Cache 30 minutes __c("files")->set($keyword_webpage,$html, 1800); }
echo $html;
挂件缓存
<?php // use Files Cache for Whole Page / Widget $cache = phpFastCache("files");
$html = $cache->widget_1;
if($html == null) { $html = Render Your Page || Widget || "Hello World"; // Save to Cache 30 minutes $cache->widget_1 = array($html, 1800); }
echo or return your $html;
同时使用多种缓存
<?php // in your config files include("phpfastcache/phpfastcache.php"); // auto | memcache | files ...etc. Will be default for $cache = __c(); phpFastCache::$storage = "auto";