关于cookbook我们可以像这样缓存元素:
echo $this->element('helpbox', array(), array('cache' => true));
缓存配置如下:
echo $this->element('helpbox', array(),
array('cache' => array('config' => 'view_long') );
如何在没有预定义配置的情况下缓存元素?如何缓存元素的持续时间?我尝试了这个,但没有成功:
echo $this->element('helpbox', array(),
array('cache' => array('time' => '+30 minutes')));
最佳答案
您需要configure cache在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,
));
之后,您可以使用定义的配置缓存您的元素:
echo $this->element('helpbox', array(), array('cache' => array('config' => 'week')));
关于php - CakePHP 缓存具有持续时间的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373576/