Свежайшие Пирожки от CakePHP по-русски

Полнейшее руководство CakePHP 1.2 на русском языке, горячие новости и полезные статьи

Caching in the Controller

Any controllers that utilize caching functionality need to include the CacheHelper in their $helpers array.

Простой текст
  1. var $helpers = array('Cache');

You also need to indicate which actions need caching, and how long each action will be cached. This is done through the $cacheAction variable in your controllers. $cacheAction should be set to an array which contains the actions you want cached, and the duration in seconds you want those views cached. The time value can be expressed in a strtotime() format. (ie. "1 hour", or "3 minutes").

Using the example of an ArticlesController, that receives a lot of traffic that needs to be cached.

Cache frequently visited Articles for varying lengths of time

Простой текст
  1. var $cacheAction = array(
  2. 'view/23/' => 21600,
  3. 'view/48/' => 36000,
  4. 'view/52' => 48000
  5. );

Cache an entire action in this case a large listing of articles

Простой текст
  1. var $cacheAction = array(
  2. 'archives/' => '60000'
  3. );

Cache every action in the controller using a strtotime() friendly time to indicate Controller wide caching time.

Простой текст
  1. var $cacheAction = "1 hour";