summaryrefslogtreecommitdiff
path: root/program/include/rcube_imap.php
diff options
context:
space:
mode:
Diffstat (limited to 'program/include/rcube_imap.php')
-rw-r--r--program/include/rcube_imap.php41
1 files changed, 33 insertions, 8 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 4cccd859a..276c07edc 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('mailboxes.metadata.' . $folder);
+ $this->clear_cache($this->metadata_cache_key($folder));
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3430,7 +3430,7 @@ class rcube_imap extends rcube_storage
return false;
}
- $this->clear_cache('mailboxes.metadata.' . $folder);
+ $this->clear_cache($this->metadata_cache_key($folder));
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
@@ -3465,15 +3465,30 @@ class rcube_imap extends rcube_storage
return null;
}
- $cache_key = 'mailboxes.metadata.' . $folder;
- if ($cached = $this->get_cache($cache_key))
- return $cached;
+ $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++;
+ }
+ }
+
+ // all requested entries are cached
+ if ($cached_count == count($entries)) {
+ return $cached_result;
+ }
if ($this->get_capability('METADATA') ||
(!strlen($folder) && $this->get_capability('METADATA-SERVER'))
) {
$res = $this->conn->getMetadata($folder, $entries, $options);
- $this->update_cache($cache_key, $res);
+ $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
return $res;
}
else if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) {
@@ -3481,7 +3496,7 @@ class rcube_imap extends rcube_storage
$res = array();
// Convert entry names
- foreach ((array)$entries as $entry) {
+ foreach ($entries as $entry) {
list($ent, $attr) = $this->md2annotate($entry);
$queries[$attr][] = $ent;
}
@@ -3493,7 +3508,7 @@ class rcube_imap extends rcube_storage
}
}
- $this->update_cache($cache_key, $res);
+ $this->update_cache($cache_key, array_merge_recursive($cached_data, $res));
return $res;
}
@@ -3502,6 +3517,16 @@ 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.
*