From 652e11f82e7af59a9c6110d75dc506113b745623 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Wed, 13 May 2015 04:46:21 -0400 Subject: [PATCH] Fix missing index update after write() call --- program/lib/Roundcube/rcube_cache_shared.php | 22 +++++++++++++++++----- program/lib/Roundcube/rcube_cache.php | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/program/lib/Roundcube/rcube_cache.php b/program/lib/Roundcube/rcube_cache.php index 41f7b33..ba7b1f5 100644 --- a/program/lib/Roundcube/rcube_cache.php +++ b/program/lib/Roundcube/rcube_cache.php @@ -354,7 +354,14 @@ } if ($this->type == 'memcache' || $this->type == 'apc') { - return $this->add_record($this->ckey($key), $data); + $result = $this->add_record($this->ckey($key), $data); + + // make sure index will be updated + if ($result && !array_key_exists($key, $this->cache_sums)) { + $this->cache_sums[$key] = true; + } + + return $result; } $key_exists = array_key_exists($key, $this->cache_sums); @@ -543,10 +550,15 @@ // Make sure index contains new keys foreach ($this->cache as $key => $value) { - if ($value !== null) { - if (array_search($key, $this->index) === false) { - $this->index[] = $key; - } + if ($value !== null && !in_array($key, $this->index)) { + $this->index[] = $key; + } + } + + // new keys added using self::write() + foreach ($this->cache_sums as $key => $value) { + if ($value === true && !in_array($key, $this->index)) { + $this->index[] = $key; } } diff --git a/program/lib/Roundcube/rcube_cache_shared.php b/program/lib/Roundcube/rcube_cache_shared.php index a85912b..2c771ee 100644 --- a/program/lib/Roundcube/rcube_cache_shared.php +++ b/program/lib/Roundcube/rcube_cache_shared.php @@ -348,7 +348,14 @@ } if ($this->type == 'memcache' || $this->type == 'apc') { - return $this->add_record($this->ckey($key), $data); + $result = $this->add_record($this->ckey($key), $data); + + // make sure index will be updated + if ($result && !array_key_exists($key, $this->cache_sums)) { + $this->cache_sums[$key] = true; + } + + return $result; } $key_exists = array_key_exists($key, $this->cache_sums); @@ -531,10 +538,15 @@ // Make sure index contains new keys foreach ($this->cache as $key => $value) { - if ($value !== null) { - if (array_search($key, $this->index) === false) { - $this->index[] = $key; - } + if ($value !== null && !in_array($key, $this->index)) { + $this->index[] = $key; + } + } + + // new keys added using self::write() + foreach ($this->cache_sums as $key => $value) { + if ($value === true && !in_array($key, $this->index)) { + $this->index[] = $key; } } -- Gitblit v1.9.1