【问题标题】:Zend\Cache\Storage\Adapter clearByTags Tag with parameters in ZF2Zend\Cache\Storage\Adapter clearByTags 标记与 ZF2 中的参数
【发布时间】:2015-02-05 12:48:09
【问题描述】:

我正在使用 bramstroker 的 StrokerCache Zend Framework 2 模块,它本身使用 Zend\Cache 并具有方法 clearByTags()

如果我想清除缓存,以下工作正常:

public function fooAction()
{
    $cs = $this->getServiceLocator()->get('strokercache_service');
    var_dump($cs->clearByTags(array(
        'controller_ClientCms\Controller\Cms'           
    )));
}

但是,如果我想包含参数怎么办?

    $cs->clearByTags(array(
        'controller_ClientCms\Controller\Cms,param_action:index,param_client:foo'           
    ));

...不起作用

缓存目录中的标记文件如下所示:

strokercache_route_home/client
strokercache_controller_ClientCms\Controller\Cms
strokercache_param_action_index
strokercache_param_client_foo

【问题讨论】:

  • 我没有使用过该库,尽管文档说明您可以使用param_<paramname>_<paramvalue> 格式从缓存中清除参数,但是您的示例显示param_<paramname>:<paramvalue>
  • 谢谢,你的提示试过了,还是不行。

标签: php caching zend-framework2 zend-cache


【解决方案1】:

答案很简单:请使用ever标签作为自己的数组元素:

$cs->clearByTags(array(
    'controller_ClientCms\Controller\Cms',
    'param_action_index',
    'param_client_foo',
));

由于我不使用该模块,我无法对其进行测试,但经过快速代码审查后,这应该可以工作。见https://github.com/bramstroker/zf2-fullpage-cache/blob/master/src/StrokerCache/Controller/CacheController.php#L41

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    • 2016-09-02
    • 2012-05-02
    • 1970-01-01
    相关资源
    最近更新 更多