Reputation: 34006
Regarding to cookbook we can cache elements like this:
echo $this->element('helpbox', array(), array('cache' => true));
Caching with configuration is like this:
echo $this->element('helpbox', array(),
array('cache' => array('config' => 'view_long') );
How can I cache elements without predefined configuration ? How can I cache duration to elements? I tried this, but didn't work:
echo $this->element('helpbox', array(),
array('cache' => array('time' => '+30 minutes')));
Upvotes: 2
Views: 3289
Reputation: 581
Since you can only reference named cache configurations now, if you want to clear the cached element programmatically, you need to use Cache::delete() with the element name and key.
I wrote a blog post about this. There's also some more detail in the relevant CakePHP forum thread.
(8/31/14) I haven't checked if this is still the behavior in CakePHP 2.5.
Upvotes: 0
Reputation: 27594
You need to configure cache in app/Config/bootstrap.php
:
Cache::config('hour', array(
'engine' => 'File',
'duration' => '+1 hours',
'path' => CACHE,
'prefix' => 'cake_short_'
));
Cache::config('week', array(
'engine' => 'File',
'duration' => '+1 week',
'probability' => 100,
'path' => CACHE . 'long' . DS,
));
after this you can cache your element using defined configuration:
echo $this->element('helpbox', array(), array('cache' => array('config' => 'week')));
Upvotes: 2