From c60b1d890d203cf719f62c8e8674445d9cf20554 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 23 Jun 2013 20:31:40 +0200 Subject: [PATCH] Fixed wildcard clearing for memcached --- .../source/MemcachedCacheSource.class.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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; + } } -- 2.20.1