Try phpFastCache.com
This is example, simple.
Caching your CSS can do like this:
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 Cache whole web page: You can use phpFastCache to cache the whole webpage easy too. This is simple example, but in real code, you should split it to 2 files: cache_start.php and cache_end.php. The cache_start.php will store the beginning code until ob_start(); and the cache_end.php will start from GET HTML WEBPAGE. Then, your index.php will include cache_start.php on beginning and cache_end.php at the end of file.
<?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;
?>
Reduce Database Calls
PHP Caching Class For Database : Your website have 10,000 visitors who are online, and your dynamic page have to send 10,000 same queries to database on every page load. With phpFastCache, your page only send 1 query to DB, and use the cache to serve 9,999 other visitors.
<?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
}
?>