Cache_Lite cache php export html

Cache_Lite 是一個簡單又好用的cache套件,當網站流量的大時候或是,或是不需要每次更新PHP產生的HTML時,這時候加個CACHE就可以減少PHP跟資料庫要資料連線次數,就可以加快網頁讀取的速度了。

準備

Cache_Lite 下載此套件

使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require_once(APP_REAL_PATH.'/Cache_Lite-1.7.8/Lite.php');
 
$Cache_Lite = new Cache_Lite(array('cacheDir'=>'存放cache位置','lifeTime' =>'cache存活時間'));
 
if($data = $Cache_Lite->get('cache代號')){
	echo $data;
}
else{
	ob_start();
 
	HTML...
 
	// 將存在緩衝區的html內容存入cache
	$Cache_Lite->save(ob_get_contents());
 
	ob_end_flush();
}

結論

使用 Cache_Lite 來當作網站的cache,雖然只是個很簡單的運用,不過對於網站提升速度相當有幫助。

參考資料

Related Posts with Thumbnails

相關文章

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>