我正在使用codeigniter (MVC)和extjs爲應用程序。 該應用程序包含許多帶用戶相關數據的extjs網格。我想緩存服務器json響應到特定時間。json數據緩存爲extjs網格
我有一個想法,以實現這個如下
if(cache file exists and not expired)
{
$data = read_file(cache file path);// the cache file contains json encoded data with .json extention
}
else
{
$result = call to a model function; // returns data from a mysql query
$data = json_encode($result);
//creating cache file with retrived data
wite_file(cache file path, $data)
}
echo $data; // $data is in json format
我想實現緩存這種方式。這是正確的方式嗎? 完全我想實現一個自定義的json緩存庫緩存服務器json數據extjs網格
是否有任何json緩存庫已經可用於codeigniter。 請幫助你的建議
謝謝phirschybar。我查看codeigniter緩存庫,它使用serialize將響應數據寫入緩存文件並反序列化以從緩存文件讀取數據。我嘗試用json_encode替換序列化,但它給出錯誤[json](php_json_encode)類型不受支持,編碼爲null。我認爲json_encode()不能編碼mysql結果對象。我st-rucked here.Any建議嗎? – nani1216 2011-12-29 11:36:59
你運行的是哪個版本的php? – phirschybar 2011-12-29 15:46:56
我正在運行PHP 5.3.1 – nani1216 2011-12-30 05:43:39