From: Alexander Ebert Date: Sun, 23 Jun 2013 18:31:40 +0000 (+0200) Subject: Fixed wildcard clearing for memcached X-Git-Tag: 2.0.0_Beta_4~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c60b1d890d203cf719f62c8e8674445d9cf20554;p=GitHub%2FWoltLab%2FWCF.git Fixed wildcard clearing for memcached --- diff --git a/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php index 540c9b04dd..3ae545ed6a 100644 --- a/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/MemcachedCacheSource.class.php @@ -93,9 +93,12 @@ class MemcachedCacheSource implements ICacheSource { */ public function flush($cacheName, $useWildcard) { $cacheName = $this->prefix . $cacheName; - $this->memcached->delete($cacheName); - $this->updateMaster(null, $cacheName); + $resources = ($useWildcard) ? $this->getResources('~^' . $cacheName. '(-[a-f0-9]+)?$~') : array($cacheName); + foreach ($resources as $resource) { + $this->memcached->delete($resource); + $this->updateMaster(null, $resource); + } } /** @@ -238,4 +241,29 @@ class MemcachedCacheSource implements ICacheSource { // default TTL: 3 days return (60 * 60 * 24 * 3); } + + /** + * Gets a list of resources matching given pattern. + * + * @param string $pattern + * @return array + */ + protected function getResources($pattern) { + $resources = array(); + $master = $this->memcached->get($this->prefix . 'master'); + + if ($master !== false) { + $master = @unserialize($master); + + if ($master !== false) { + foreach ($master as $index => $key) { + if (preg_match($pattern, $key)) { + $resources[] = $key; + } + } + } + } + + return $resources; + } }