From fff8e0f2aebab70b180127441fb86807099319f6 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Tue, 12 May 2015 03:09:13 -0400 Subject: [PATCH] Fix possible memcache/apc cache data consistency issues (#1490390) --- program/lib/Roundcube/rcube_cache_shared.php | 28 ++++++++++++---------------- 1 files changed, 12 insertions(+), 16 deletions(-) diff --git a/program/lib/Roundcube/rcube_cache_shared.php b/program/lib/Roundcube/rcube_cache_shared.php index 37eb4bd..e156895 100644 --- a/program/lib/Roundcube/rcube_cache_shared.php +++ b/program/lib/Roundcube/rcube_cache_shared.php @@ -260,7 +260,15 @@ } if ($this->type != 'db') { - if ($this->type == 'memcache') { + $this->load_index(); + + // Consistency check (#1490390) + if (!in_array($key, $this->index)) { + // we always check if the key exist in the index + // to have data in consistent state. Keeping the index consistent + // is needed for keys delete operation when we delete all keys or by prefix. + } + else if ($this->type == 'memcache') { $ckey = $this->ckey($key); $data = $this->db->get($ckey); @@ -441,13 +449,12 @@ /** * Adds entry into memcache/apc DB. * - * @param string $key Cache key name - * @param mxied $data Serialized cache data - * @param bollean $index Enables immediate index update + * @param string $key Cache key name + * @param mixed $data Serialized cache data * * @param boolean True on success, False on failure */ - private function add_record($key, $data, $index=false) + private function add_record($key, $data) { if ($this->type == 'memcache') { $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl); @@ -466,17 +473,6 @@ if ($this->debug) { $this->debug('store', $key, $data, $result); - } - } - - // Update index - if ($index && $result) { - $this->load_index(); - - if (array_search($key, $this->index) === false) { - $this->index[] = $key; - $data = serialize($this->index); - $this->add_record($this->ikey(), $data); } } -- Gitblit v1.9.1