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.
In the Cache documentation of the manual (1.2): http://book.cakephp.org/view/213/Cache
I would recommend that you disable caching while doing development; you'll find (hopefully not the hard way, like me) that your models and views are not changing as expected.
Read the Documentation:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With