Horde_Imap_Client_Base::_getSearchCache PHP Method

_getSearchCache() protected method

Retrieve data from the search cache.
protected _getSearchCache ( string $type, array $options ) : mixed
$type string The cache type ('search' or 'thread').
$options array The options array of the calling function.
return mixed Returns search cache metadata. If search was retrieved, data is in key 'data'. Returns null if caching is not available.
    protected function _getSearchCache($type, $options)
    {
        $status = $this->status($this->_selected, Horde_Imap_Client::STATUS_HIGHESTMODSEQ | Horde_Imap_Client::STATUS_UIDVALIDITY);
        /* Search caching requires MODSEQ, which may not be active for a
         * mailbox. */
        if (empty($status['highestmodseq'])) {
            return null;
        }
        ksort($options);
        $cache = hash('md5', $type . serialize($options));
        $cacheid = $this->getSyncToken($this->_selected);
        $ret = array();
        $md = $this->_cache->getMetaData($this->_selected, $status['uidvalidity'], array(self::CACHE_SEARCH, self::CACHE_SEARCHID));
        if (!isset($md[self::CACHE_SEARCHID]) || $md[self::CACHE_SEARCHID] != $cacheid) {
            $md[self::CACHE_SEARCH] = array();
            $md[self::CACHE_SEARCHID] = $cacheid;
            if ($this->_debug->debug && !isset($this->_temp['searchcacheexpire'][strval($this->_selected)])) {
                $this->_debug->info(sprintf('SEARCH: Expired from cache [%s]', $this->_selected));
                $this->_temp['searchcacheexpire'][strval($this->_selected)] = true;
            }
        } elseif (isset($md[self::CACHE_SEARCH][$cache])) {
            $this->_debug->info(sprintf('SEARCH: Retrieved %s from cache (%s [%s])', $type, $cache, $this->_selected));
            $ret['data'] = $md[self::CACHE_SEARCH][$cache];
            unset($md[self::CACHE_SEARCHID]);
        }
        return array_merge($ret, array('id' => $cache, 'metadata' => $md, 'type' => $type));
    }

Usage Example

Example #1
0
 /**
  */
 protected function _getSearchCache($type, $mailbox, $options)
 {
     /* Search caching requires MODSEQ, which may not be active for a
      * mailbox. */
     return empty($this->_temp['mailbox']['highestmodseq']) ? null : parent::_getSearchCache($type, $mailbox, $options);
 }