*
* @var array
*/
- protected $_listCache = array();
+ protected $_listCache = null;
+
+ /**
+ * The cache ID used to store mailbox info.
+ *
+ * @var string
+ */
+ protected $_cacheid = null;
/**
* Returns a reference to the global IMP_Folder object, only creating it
}
/**
+ * Constructor.
+ */
+ function __construct()
+ {
+ if (!empty($GLOBALS['conf']['server']['cache_folders'])) {
+ $this->_cacheid = 'imp_folder_cache|' . Auth::getAuth();
+ }
+ }
+
+ /**
* Lists folders.
*
* @param boolean $sub Should we list only subscribed folders?
*/
public function flist($sub = false, $filter = array())
{
- global $conf, $notification;
-
$inbox_entry = array(
'INBOX' => array(
'val' => 'INBOX',
return $inbox_entry;
}
- $list = array();
- $subidx = intval($sub);
-
/* Compute values that will uniquely identify this list. */
- $full_signature = md5(serialize(array($subidx, $filter)));
+ $sig = md5(serialize(array(intval($sub), $filter)));
/* Either get the list from the cache, or go to the IMAP server to
obtain it. */
- if ($conf['server']['cache_folders']) {
- $sessionOb = &Horde_SessionObjects::singleton();
- if (!isset($_SESSION['imp']['cache']['folder_cache'])) {
- $_SESSION['imp']['cache']['folder_cache'] = array();
- }
- $folder_cache = &$_SESSION['imp']['cache']['folder_cache'];
- if (isset($folder_cache[$full_signature])) {
- $data = $sessionOb->query($folder_cache[$full_signature]);
- if ($data) {
- return $data;
+ $cache = null;
+ if (is_null($this->_listCache)) {
+ if (!is_null($this->_cacheid) && ($cache = &IMP::getCacheOb())) {
+ $ret = $cache->get($this->_cacheid, 3600);
+ if (!empty($ret)) {
+ $this->_listCache = unserialize($ret);
}
}
+
+ if (empty($this->_listCache)) {
+ $this->_listCache = array();
+ }
+ }
+
+ if (isset($this->_listCache[$sig])) {
+ return $this->_listCache[$sig];
}
require_once IMP_BASE . '/lib/IMAP/Tree.php';
$imaptree = &IMP_Tree::singleton();
- if (!isset($this->_listCache[$subidx])) {
- $list_mask = IMPTREE_FLIST_CONTAINER | IMPTREE_FLIST_OB;
- if (!$sub) {
- $list_mask |= IMPTREE_FLIST_UNSUB;
- }
- $this->_listCache[$subidx] = $imaptree->folderList($list_mask);
+ $list_mask = IMPTREE_FLIST_CONTAINER | IMPTREE_FLIST_OB;
+ if (!$sub) {
+ $list_mask |= IMPTREE_FLIST_UNSUB;
}
+ $flist = $imaptree->folderList($list_mask);
- foreach ($this->_listCache[$subidx] as $ob) {
+ reset($flist);
+ while (list(,$ob) = each($flist)) {
if (in_array($ob['v'], $filter)) {
continue;
}
$list = $inbox_entry + $list;
}
+ $this->_listCache[$sig] = $list;
+
/* Save in cache, if needed. */
- if ($conf['server']['cache_folders']) {
- $folder_cache[$full_signature] = $sessionOb->storeOid($list, false);
+ if (!is_null($cache)) {
+ $cache->set($this->_cacheid, serialize($this->_listCache), 3600);
}
return $list;
*/
public function clearFlistCache()
{
- if (!empty($_SESSION['imp']['cache']['folder_cache'])) {
- $sessionOb = &Horde_SessionObjects::singleton();
- foreach ($_SESSION['imp']['cache']['folder_cache'] as $val) {
- $sessionOb->setPruneFlag($val, true);
- }
- $_SESSION['imp']['cache']['folder_cache'] = array();
+ if (!is_null($this->_cacheid) && ($cache = &IMP::getCacheOb())) {
+ $cache->expire($this->_cacheid);
}
$this->_listCache = array();
}
protected function _onDelete($deleted)
{
/* Reset the folder cache. */
- unset($_SESSION['imp']['cache']['folder_cache']);
+ $this->clearFlistCache();
/* Recreate Virtual Folders. */
$GLOBALS['imp_search']->sessionSetup(true);
}
/* Reset the folder cache. */
- if ($conf['server']['cache_folders']) {
- unset($_SESSION['imp']['cache']['folder_cache']);
- }
+ $this->clearFlistCache();
/* Update the IMAP_Tree object. */
require_once IMP_BASE . '/lib/IMAP/Tree.php';
$imaptree->subscribe($subscribed);
/* Reset the folder cache. */
- unset($_SESSION['imp']['cache']['folder_cache']);
+ $this->clearFlistCache();
}
return $return_value;
$imaptree->unsubscribe($unsubscribed);
/* Reset the folder cache. */
- unset($_SESSION['imp']['cache']['folder_cache']);
+ $this->clearFlistCache();
}
return $return_value;