2

关于食谱,我们可以缓存这样的元素:

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')));
4

2 回答 2

2

您需要在以下位置配置缓存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')));
于 2012-07-07T08:49:00.103 回答
0

由于您现在只能引用命名缓存配置,因此如果您想以编程方式清除缓存的元素,您需要使用 Cache::delete() 与元素名称和键。

我写了一篇关于这个的博客文章。在相关的 CakePHP 论坛主题中还有一些更详细的信息。

(8/31/14) 我还没有检查这是否仍然是 CakePHP 2.5 中的行为。

于 2012-12-17T14:12:44.620 回答