From e17217b14ae5dd7912521caa737725daf5168d5c Mon Sep 17 00:00:00 2001 From: Andrej Hudec Date: Fri, 27 Apr 2012 22:40:33 +0200 Subject: [PATCH] [HttpKernel] Remove destructive flush() from memcache(d) storage profilers --- .../Profiler/BaseMemcacheProfilerStorage.php | 29 +++++++++++++++++-- .../Profiler/MemcacheProfilerStorage.php | 4 +-- .../Profiler/MemcachedProfilerStorage.php | 4 +-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/BaseMemcacheProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/BaseMemcacheProfilerStorage.php index 5a54d62461..ba6bf1532d 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/BaseMemcacheProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/BaseMemcacheProfilerStorage.php @@ -95,7 +95,28 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface */ public function purge() { - $this->flush(); + // delete only items from index + $indexName = $this->getIndexName(); + + $indexContent = $this->getValue($indexName); + + if (!$indexContent) { + return false; + } + + $profileList = explode("\n", $indexContent); + + foreach ($profileList as $item) { + if ($item == '') { + continue; + } + + if (false !== $pos = strpos($item, "\t")) { + $this->delete($this->getItemName(substr($item, 0, $pos))); + } + } + + return $this->delete($indexName); } /** @@ -172,11 +193,13 @@ abstract class BaseMemcacheProfilerStorage implements ProfilerStorageInterface abstract protected function setValue($key, $value, $expiration = 0); /** - * Flush all existing items at the memcache server + * Delete item from the memcache server + * + * @param string $key * * @return boolean */ - abstract protected function flush(); + abstract protected function delete($key); /** * Append data to an existing item on the memcache server diff --git a/src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php index dfcf48705b..ca79405cd7 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/MemcacheProfilerStorage.php @@ -69,9 +69,9 @@ class MemcacheProfilerStorage extends BaseMemcacheProfilerStorage /** * {@inheritdoc} */ - protected function flush() + protected function delete($key) { - return $this->getMemcache()->flush(); + return $this->getMemcache()->delete($key); } /** diff --git a/src/Symfony/Component/HttpKernel/Profiler/MemcachedProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/MemcachedProfilerStorage.php index 4b45c6be8a..6d76127299 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/MemcachedProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/MemcachedProfilerStorage.php @@ -73,9 +73,9 @@ class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage /** * {@inheritdoc} */ - protected function flush() + protected function delete($key) { - return $this->getMemcached()->flush(); + return $this->getMemcached()->delete($key); } /**