{ES} - 7.2.4 Caching en los Controllers
Cualquier controlador que utilice la funcionalidad de caching necesita incluir el CacheHelper en el arreglo $helpers.
var $helpers = array('Cache');
var $helpers = array('Cache');
Necesitas ademas indicar cuales acciones necesitan caching, y cuanto tiempo durará cacheada cada acción. Esto se hace a traves de la variable $cacheAction en tus controladores. $cacheAction debería ser configurada como un arreglo el cual contiene las acciones a ser cacheadas y la duracion en segundos que deben permanecer en tal condicion. EL tiempo puede expresarse en formato strtotime(). (ie. "1 hour", o "3 minutes").
Usando como ejemplo ArticlesController, que recibe un gran tráfico que necesita cachearse.
Por ejemplo, cachear los articulos visitados frecuentemente por diversos periodos de tiempo
var $cacheAction = array( 'view/23/' => 21600, 'view/48/' => 36000, 'view/52' => 48000 );
var $cacheAction = array('view/23/' => 21600,'view/48/' => 36000,'view/52' => 48000);
Hacer caching de una acción completa en este caso un listado de articulos
var $cacheAction = array( 'archives/' => '60000' );
var $cacheAction = array('archives/' => '60000');
Cachear todas las acciones del controlador usando un formato amigable strtotime() para indicar el tiempo de cacheo.
var $cacheAction = "1 hour";
var $cacheAction = "1 hour";
{EN} - 7.2.4 Caching in the Controller
Any controllers that utilize caching functionality need to include the CacheHelper in their $helpers array.
var $helpers = array('Cache');
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
var $cacheAction = array( 'view/23' => 21600, 'view/48' => 36000, 'view/52' => 48000 );
var $cacheAction = array('view/23' => 21600,'view/48' => 36000,'view/52' => 48000);
Remember to use your routes in the $cacheAction if you have any.
Cache an entire action in this case a large listing of articles
var $cacheAction = array( 'archives/' => '60000' );
var $cacheAction = array('archives/' => '60000');
Cache every action in the controller using a strtotime() friendly time to indicate Controller wide caching time.
var $cacheAction = "1 hour";
var $cacheAction = "1 hour";
You can also enable controller/component callbacks for cached views created with CacheHelper. To do so you must use the array format for $cacheAction and create an array like the following:
var $cacheAction = array(
'view' => array('callbacks' => true, 'duration' => 21600),
'add' => array('callbacks' => true, 'duration' => 36000),
'index' => array('callbacks' => true, 'duration' => 48000)
);
var $cacheAction = array('view' => array('callbacks' => true, 'duration' => 21600),'add' => array('callbacks' => true, 'duration' => 36000),'index' => array('callbacks' => true, 'duration' => 48000));
By setting callbacks => true you tell CacheHelper that you want the generated files to create the components and models for the controller. As well as, fire the component initialize, controller beforeFilter, and component startup callbacks.
callbacks => true partly defeats the purpose of caching. This is also the reason it is disabled by default.
Diferencias
| Lines: 1-35 | Lines: 1-24 | ||
| - | <title>Caching in the Controller</title> <p>Any controllers that utilize caching functionality need to include the CacheHelper in their $helpers array.</p> |
+ | <title>Caching en los Controllers</title> <p>Cualquier controlador que utilice la funcionalidad de caching necesita incluir el CacheHelper en el arreglo $helpers.</p> |
| <pre> | <pre> | ||
| var $helpers = array('Cache'); | var $helpers = array('Cache'); | ||
| </pre> | </pre> | ||
| - | <p>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"). | + | <p>Necesitas ademas indicar cuales acciones necesitan caching, y cuanto tiempo durará cacheada cada acción. Esto se hace a traves de la variable $cacheAction en tus controladores. $cacheAction debería ser configurada como un arreglo el cual contiene las acciones a ser cacheadas y la duracion en segundos que deben permanecer en tal condicion. EL tiempo puede expresarse en formato strtotime(). (ie. "1 hour", o "3 minutes"). |
| </p> | </p> | ||
| - | <p>Using the example of an ArticlesController, that receives a lot of traffic that needs to be cached.</p> <p>Cache frequently visited Articles for varying lengths of time</p> |
+ | <p>Usando como ejemplo ArticlesController, que recibe un gran tráfico que necesita cachearse.</p> <p>Por ejemplo, cachear los articulos visitados frecuentemente por diversos periodos de tiempo</p> |
| <pre> | <pre> | ||
| var $cacheAction = array( | var $cacheAction = array( | ||
| - | 'view/23' => 21600, 'view/48' => 36000, |
+ | 'view/23/' => 21600, 'view/48/' => 36000, |
| 'view/52' => 48000 | 'view/52' => 48000 | ||
| ); | ); | ||
| </pre> | </pre> | ||
| - | <p>Remember to use your routes in the $cacheAction if you have any.</p> <p>Cache an entire action in this case a large listing of articles</p> |
+ | <p>Hacer caching de una acción completa en este caso un listado de articulos</p> |
| <pre> | <pre> | ||
| var $cacheAction = array( | var $cacheAction = array( | ||
| 'archives/' => '60000' | 'archives/' => '60000' | ||
| ); | ); | ||
| </pre> | </pre> | ||
| - | <p>Cache every action in the controller using a strtotime() friendly time to indicate Controller wide caching time.</p> | + | <p>Cachear todas las acciones del controlador usando un formato amigable strtotime() para indicar el tiempo de cacheo.</p> |
| <pre>var $cacheAction = "1 hour";</pre> | <pre>var $cacheAction = "1 hour";</pre> | ||
| - | <p>You can also enable controller/component callbacks for cached views created with <code>CacheHelper</code>. To do so you must use the array format for <code>$cacheAction</code> and create an array like the following: | ||
| - | <pre> | ||
| - | var $cacheAction = array( | ||
| - | 'view' => array('callbacks' => true, 'duration' => 21600), | ||
| - | 'add' => array('callbacks' => true, 'duration' => 36000), | ||
| - | 'index' => array('callbacks' => true, 'duration' => 48000) | ||
| - | ); | ||
| - | </pre> | ||
| - | <p>By setting <code>callbacks => true</code> you tell CacheHelper that you want the generated files to create the components and models for the controller. As well as, fire the component initialize, controller beforeFilter, and component startup callbacks.</p> | ||
| - | <p class="note"Setting <code>callbacks => true</code> partly defeats the purpose of caching. This is also the reason it is disabled by default.</p> | ||


























