Fix possible memcache/apc cache data consistency issues (#1490390)

And removed unused code
pull/247/merge
Aleksander Machniak 10 years ago
parent 28b1cb04b6
commit fff8e0f2ae

@ -26,6 +26,7 @@ CHANGELOG Roundcube Webmail
- Fix bug where preview_pane setting wasn't always saved into user preferences (#1490362) - Fix bug where preview_pane setting wasn't always saved into user preferences (#1490362)
- Fix bug where messages count was not updated after message move/delete with skip_deleted=false (#1490372) - Fix bug where messages count was not updated after message move/delete with skip_deleted=false (#1490372)
- Fix security issue in contact photo handling (#1490379) - Fix security issue in contact photo handling (#1490379)
- Fix possible memcache/apc cache data consistency issues (#1490390)
RELEASE 1.1.1 RELEASE 1.1.1
------------- -------------

@ -265,7 +265,15 @@ class rcube_cache
} }
if ($this->type != 'db') { 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); $ckey = $this->ckey($key);
$data = $this->db->get($ckey); $data = $this->db->get($ckey);
@ -418,13 +426,7 @@ class rcube_cache
} }
// Remove keys by name prefix // Remove keys by name prefix
else if ($prefix_mode) { else if ($prefix_mode) {
// handle data inconsistency: it may happen that index foreach ($this->index as $k) {
// contains not all existing cache entries, here we could
// handle at least these that were used before the index was read
$index = array_merge($this->index, array_keys($this->cache));
$index = array_unique($index);
foreach ($index as $k) {
if (strpos($k, $key) === 0) { if (strpos($k, $key) === 0) {
$this->delete_record($k); $this->delete_record($k);
} }
@ -460,13 +462,12 @@ class rcube_cache
/** /**
* Adds entry into memcache/apc DB. * Adds entry into memcache/apc DB.
* *
* @param string $key Cache key name * @param string $key Cache key name
* @param mxied $data Serialized cache data * @param mixed $data Serialized cache data
* @param bollean $index Enables immediate index update
* *
* @param boolean True on success, False on failure * @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') { if ($this->type == 'memcache') {
$result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl); $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
@ -487,17 +488,6 @@ class rcube_cache
} }
} }
// 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);
}
}
return $result; return $result;
} }

@ -260,7 +260,15 @@ class rcube_cache_shared
} }
if ($this->type != 'db') { 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); $ckey = $this->ckey($key);
$data = $this->db->get($ckey); $data = $this->db->get($ckey);
@ -441,13 +449,12 @@ class rcube_cache_shared
/** /**
* Adds entry into memcache/apc DB. * Adds entry into memcache/apc DB.
* *
* @param string $key Cache key name * @param string $key Cache key name
* @param mxied $data Serialized cache data * @param mixed $data Serialized cache data
* @param bollean $index Enables immediate index update
* *
* @param boolean True on success, False on failure * @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') { if ($this->type == 'memcache') {
$result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl); $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
@ -469,17 +476,6 @@ class rcube_cache_shared
} }
} }
// 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);
}
}
return $result; return $result;
} }

Loading…
Cancel
Save