嘗試phpFastCache.com
這是例子,簡單。 緩存你的CSS可以這樣做:
require_once("phpfastcache/phpfastcache.php");
$css = __c()->get("csspage.user_id_something");
if($css == null) {
// handle your css function here
$css = "your handle function here";
// write to cache 1 hour
__c()->set("csspage.user_id_something", $css, 3600);
}
echo $css;
PHP緩存整個網頁:您可以使用phpFastCache緩存整個網頁很容易。這是一個簡單的例子,但是在實際的代碼中,你應該將它分成兩個文件:cache_start.php和cache_end.php。 cache_start.php將存儲開始代碼,直到ob_start();並且cache_end.php將從GET HTML WEBPAGE開始。然後,你的index.php將包含開始處的cache_start.php和文件結尾處的cache_end.php。
<?php
// use Files Cache for Whole Page/Widget
// keyword = Webpage_URL
$keyword_webpage = md5($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
$html = __c("files")->get($keyword_webpage);
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緩存類數據庫:您的網站有10,000個觀衆誰是在線,你的動態頁面都送萬個同查詢數據庫中每個頁面加載。使用phpFastCache,您的頁面只會向數據庫發送1個查詢,並使用緩存爲9,999個其他訪問者提供服務。
<?php
// In your config file
include("phpfastcache/phpfastcache.php");
phpFastCache::setup("storage","auto");
// 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->product_page;
if($products == null) {
$products = YOUR DB QUERIES || GET_PRODUCTS_FUNCTION;
// set products in to cache in 600 seconds = 10 minutes
$cache->product_page = array($products,600);
}
foreach($products as $product) {
// Output Your Contents HERE
}
?>
什麼是動態的樣式表,需要你檢查,看看是否需要刷新CSS? – frustratedtech
Expires是一個強大的緩存機制,所以如果你還沒有實現某種緩存清除,你將很難修復它的問題。 – brezanac
這可能有助於http://stackoverflow.com/questions/3777974/php-compress-static-css-file-with-gzip – kodeart