Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use cache in CakePHP?

I want to use cache in CakePHP. How do I use it?

like image 721
user130415 Avatar asked Jun 29 '09 12:06

user130415


3 Answers

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.

like image 129
nanoman Avatar answered Oct 28 '22 02:10

nanoman


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.

like image 3
gravyface Avatar answered Oct 28 '22 02:10

gravyface


Read the Documentation:

  • http://book.cakephp.org/view/213/Cache
  • http://book.cakephp.org/view/325/View-Caching
  • http://book.cakephp.org/search/cache
like image 2
Sampson Avatar answered Oct 28 '22 02:10

Sampson