如何在CakePHP中使用缓存? [英] How do I use cache in CakePHP?
本文介绍了如何在CakePHP中使用缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在缓存 .org /rel =nofollow> CakePHP 。如何使用它?
I want to use cache in CakePHP. How do I use it?
推荐答案
if(!($cachedPosts = Cache::read('cached_posts'))) {
$cachedPosts = $this->Post->find('all');
Cache::write('cached_posts', $cachedPosts);
}
在此代码示例中,查看是否有数据缓存 - 从数据库中检索它,并将其写入缓存。在下一个请求中,数据来自缓存,而不是来自数据库。
In this code example you look if you have the data cached - if not, retrieve it from the database, and write it to the cache. On the next request, the data will come from the cache, not from the database.
这篇关于如何在CakePHP中使用缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文