summaryrefslogtreecommitdiff
path: root/program/include/rcube_imap.php
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-05-15 13:48:20 +0200
committerThomas Bruederli <thomas@roundcube.net>2012-05-15 13:48:20 +0200
commit67f18e561075f18a1af7f5eaa89d49f4bd400e16 (patch)
treeae493433876cc74164a34df093f3e681ef9f305d /program/include/rcube_imap.php
parentceb5b56c3b8db37425338e9c2661c5c4bc4ac069 (diff)
parent938925f320de5df1e551373efd83842aad3b4a07 (diff)
Merge branch 'master' of github.com:roundcube/roundcubemail
Diffstat (limited to 'program/include/rcube_imap.php')
-rw-r--r--program/include/rcube_imap.php54
1 files changed, 21 insertions, 33 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 276c07edc..7a86b170b 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -3396,7 +3396,7 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache($this->metadata_cache_key($folder));
+ $this->clear_cache('mailboxes.metadata.', true);
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3430,9 +3430,9 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache($this->metadata_cache_key($folder));
+ $this->clear_cache('mailboxes.metadata.', true);
- if ($this->get_capability('METADATA') ||
+ if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
return $this->conn->deleteMetadata($folder, $entries);
@@ -3461,35 +3461,31 @@ class rcube_imap extends rcube_storage
*/
public function get_metadata($folder, $entries, $options=array())
{
- if (!$this->check_connection()) {
- return null;
- }
-
$entries = (array)$entries;
- // check cached data
- $cache_key = $this->metadata_cache_key($folder);
- $cached_data = (array)$this->get_cache($cache_key);
- $cached_result = array();
- $cached_count = 0;
- foreach ($entries as $entry_key) {
- if (isset($cached_data[$folder][$entry_key])) {
- $cached_result[$folder][$entry_key] = $cached_data[$folder][$entry_key];
- $cached_count++;
- }
+ // create cache key
+ // @TODO: this is the simplest solution, but we do the same with folders list
+ // maybe we should store data per-entry and merge on request
+ sort($options);
+ sort($entries);
+ $cache_key = 'mailboxes.metadata.' . $folder;
+ $cache_key .= '.' . md5(serialize($options).serialize($entries));
+
+ // get cached data
+ $cached_data = $this->get_cache($cache_key);
+
+ if (is_array($cached_data)) {
+ return $cached_data;
}
- // all requested entries are cached
- if ($cached_count == count($entries)) {
- return $cached_result;
+ if (!$this->check_connection()) {
+ return null;
}
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
$res = $this->conn->getMetadata($folder, $entries, $options);
- $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
- return $res;
}
else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
$queries = array();
@@ -3507,8 +3503,10 @@ class rcube_imap extends rcube_storage
$res = array_merge_recursive($res, $result);
}
}
+ }
- $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
+ if (isset($res)) {
+ $this->update_cache($cache_key, $res);
return $res;
}
@@ -3517,16 +3515,6 @@ class rcube_imap extends rcube_storage
/**
- * Helper method to compose the cache key for the given folder metadata
- */
- protected function metadata_cache_key($folder)
- {
- $suffix = $folder == '' ? '[SERVER]' : (strpos($folder, '*') === false ? $folder : '');
- return 'mailboxes.metadata.' . $suffix;
- }
-
-
- /**
* Converts the METADATA extension entry name into the correct
* entry-attrib names for older ANNOTATEMORE version.
*