phpcachingzend-framework2zend-cache

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

Solution

  • 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