Question

I have a multilingual site (culture depends on the host URL eg.: uk.site.com, fr.site.com etc.). I'm caching a partial in the frontend and set its cache key. Then from the model I do something like:

$cacheManager = sfContext::getInstance()->getViewCacheManager();
$cacheUri = $cacheManager->getPartialUri($module, $action, $cacheKey);
$cacheManager->remove($cacheUri, *); //second param is to clear this cache for all hosts
// $cacheManager->remove($cacheUri); when is like that it works for fine but only for the domain it's been called from.

The code above calls the sf core method sfMemCache->removePattern($pattern) which has:

$regexp = self::patternToRegexp($this->getOption('prefix').$pattern);
foreach ($this->getCacheInfo() as $key)
{
  if (preg_match($regexp, $key))
  {
    $this->remove(substr($key, strlen($this->getOption('prefix'))));
  }
}

and $this->getCacheInfo() is always empty and it can't clear anything. It always throw "To use the "removePattern" method, you must set the "storeCacheInfo" option to "true"." exception. I cant find where does that cacheInfos() has to be filled or what exactly is its role.

Simplified version of my question is: "Why is $this->getCacheInfo empty"

Était-ce utile?

La solution

If the removePattern method is throwing that error then memcached is not configured correctly in your factories.yml configuration.

The answer you want is discussed on this page under the heading 'Alternative Caching storage'

You need to set your class and parameter correctly to use the removePattern method. For instance:

view_cache:
    class: sfMemcacheCache
    param:
      host: localhost
      port: 11211
      persistent: true
      storeCacheInfo: true

You will also need to insure that the memcached daemon is operational. If memcached is running on the same host as the script in it's default configuration then the above settings should be fine. If you are running memcached on a separate host or you have multiple hosts sharing a memcached service then you must insure your host, port and firewall settings are correct for your environment.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top