缓存 CakePHP 元素关于参数


Caching CakePHP elements regarding to argument

我需要缓存 CakePHP 元素。但是我的元素因参数而异。myElement 采用一个名为 $type 的参数。
$type更改时,我的元素的内容会发生变化。

我这样称呼我的元素:echo $this->element('myElement', array('type' => 2), array('cache' => true));
在另一个页面中,如下所示:
echo $this->element('myElement', array('type' => 3), array('cache' => true));

当我通过将调试模式增加到 2 来启用缓存时,这两个元素都给了我相同的输出。是否可以缓存一个元素的不同版本?

echo $this->element('myElement', array('type' => 3), array('cache' => array('key' => 'my_element_type_3'));

'cache'键可以采用具有 configkey 的数组。将key设置为唯一名称(在名称中追加类型)应使其唯一。

如果元素没有太多共同点,则为每个元素使用不同的元素文件可能更容易。 $this->element('myElementType3'); $this->element('myElementType2');