我使用Simple PHP Cache类并在管理面板中添加新文章时将MySql结果设置为文件缓存。赞:
缓存文件:(article.txt)
{"204":{"time":1410385682,"expire":0,"data":{"action":["0","description test","title test","1","2",1410530579,"6",205]},
{"205":{"time":1410385682,"expire":0,"data":{"action":["0","description test","title test","1","2",1410530579,"6",205]},
{"207":{"time":1410385682,"expire":0,"data":{"action":["0","description test","title test","1","2",1410530579,"6",205]}
}}
对于检索,我可以使用此方法从文件中检索数据:
// cache file with the name 'article'
$c->setCache('article');
// get cached data by its key (id)
$result = $c->retrieve('204');
// display the cached array
echo '<pre>';
print_r($result);
echo '<pre>';
OR
// grab array entry
$description = $result['description'];
这很有效,但我不明白如何从PHP
循环或php if/else
或获取查询列表中的缓存文件中检索日期。
示例:
在页面中我需要打印所有文章的列表并按日期排序。在MySQL中像这样检索数据:
$result = SQL::FETCH("SELECT * FROM DATABASE WHERE id = $id and active = 1 LIMIT 20 ORDER BY timestamp DESC");
foreach ($result as $row){
echo $row['id];
}
现在,如何处理缓存文件并检索我的示例结果数据?!(列出所有文章并按日期排序)??
PHP CACHE HERE