View caching
Caching your views is an important step towards improving the loading time of your application as content is served faster. This can have a noticeable effect on users, as they get to content and features quicker, making them a bit happier.
In this recipe, we'll build an example scenario that shows off some of the base caching features of CakePHP.
Getting ready
First, open your core.php
file in app/Config/
, make sure the following line is not commented out, and set it to true
:
Configure::write('Cache.check', true);
This configuration option enables and generates cached view files for requests.
Also, in your bootstrap.php
file in app/Config/
, make sure that CacheDispatcher
is set in your Dispatcher.filters
configuration. Take a look at the following example:
Configure::write('Dispatcher.filters', array( 'AssetDispatcher', 'CacheDispatcher' ));
We'll then need a controller to work with. So, create a TimestampsController.php
file in app/Controller/
, and add the following content:
<...