简体   繁体   中英

Zend\Cache\Storage\Adapter clearByTags Tag with parameters in ZF2

I'm using bramstroker's StrokerCache Zend Framework 2 module which itself uses Zend\\Cache and has the method clearByTags() .

If I want to clear cache, th following works fine:

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

However, what if I want to include parameters?

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

...does not work.

Here is how the tag-file in the cache directory looks like:

strokercache_route_home/client
strokercache_controller_ClientCms\Controller\Cms
strokercache_param_action_index
strokercache_param_client_foo

The answare is simple: Please use ever tag as an own array element:

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

As I don't use the module I can't test it but after a quick code review this should work. see https://github.com/bramstroker/zf2-fullpage-cache/blob/master/src/StrokerCache/Controller/CacheController.php#L41

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM