/** * TODO */ protected function _getAddressBook(array $fields = array()) { $key = 'turba_fb_getAddressBook|' . $GLOBALS['registry']->getAuth() . '|' . md5(implode('.', $fields)); if ($values = $this->_cache->get($key, 3600)) { return json_decode($values, true); } $cleanfields = implode(', ', $this->_prepareFields($fields)); try { $fql = 'SELECT ' . $cleanfields . ' FROM user WHERE uid IN (' . 'SELECT uid2 FROM friend WHERE uid1=' . $this->_facebook->auth->getLoggedInUser() . ')'; $results = $this->_facebook->fql->run($fql); } catch (Horde_Service_Facebook_Exception $e) { Horde::log($e, 'ERR'); if ($e->getCode() == Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY) { throw new Turba_Exception(_("You are not connected to Facebook. Create a Facebook connection in the Global Preferences.")); } throw new Turba_Exception($e); } // Now pull out the results that are arrays $addressbook = array(); foreach ($results as &$result) { $addressbook[$result['uid']] = $this->_fqlToTurba($fields, $result); } $this->_cache->set($key, json_encode($addressbook)); return $addressbook; }
/** * Returns the cached group list. * * @param string $user A user name. * * @return array The group list or null if not cached. */ protected function _getListCache($user = null) { $sig = $this->_sig('list'); if (!is_null($user)) { $sig .= '_' . $user; } try { if ($list = $this->_cache->get($sig, 0)) { return @unserialize($list); } } catch (Horde_Cache_Exception $e) { } }
/** * Get user groups */ public function getGroups() { $groups = $this->_cache->get('folksGroups' . $this->_user, $GLOBALS['conf']['cache']['default_lifetime']); if ($groups) { return unserialize($groups); } else { $groups = $this->_getGroups(); if ($groups instanceof PEAR_Error) { return $groups; } $this->_cache->set('folksGroups' . $this->_user, serialize($groups)); return $groups; } }
/** * Returns a Horde_History_Log corresponding to the named history entry, * with the data retrieved appropriately. * * @param string $guid The name of the history entry to retrieve. * * @return Horde_History_Log A Horde_History_Log object. * * @throws Horde_History_Exception */ public function getHistory($guid) { if (!is_string($guid)) { throw new Horde_History_Exception('The guid needs to be a string!'); } if ($this->_cache && ($history = @unserialize($this->_cache->get('horde:history:' . $guid, 0)))) { return $history; } $history = $this->_getHistory($guid); if ($this->_cache) { $this->_cache->set('horde:history:' . $guid, serialize($history), 0); } return $history; }
/** * List the available library descriptions. * * @return array The list of libraries from pear.horde.org. */ public function listDescriptions() { // Cache the list from pear.horde.org for one day if ($descriptions = $this->_cache->get(__CLASS__ . '::descriptions2', 86400)) { return unserialize($descriptions); } $components = $this->_getComponents(); $descriptions = array(); foreach ($components as $component) { $descriptions[$component->name] = $component->description; } ksort($descriptions); $this->_cache->set(__CLASS__ . '::descriptions2', serialize($descriptions)); return $descriptions; }
/** * Load the slicemap for a given mailbox. The slicemap contains * the uidvalidity information, the UIDs->slice lookup table, and any * metadata that needs to be saved for the mailbox. * * @param string $mailbox The mailbox. * @param integer $uidvalid The IMAP uidvalidity value of the mailbox. */ protected function _loadSliceMap($mailbox, $uidvalid = null) { if (!isset($this->_slicemap[$mailbox]) && ($data = $this->_cache->get($this->_getCid($mailbox, 'slicemap'), 0)) !== false && ($slice = @unserialize($data)) && is_array($slice)) { $this->_slicemap[$mailbox] = $slice; } if (isset($this->_slicemap[$mailbox])) { $ptr =& $this->_slicemap[$mailbox]; if (is_null($ptr['d']['uidvalid'])) { $ptr['d']['uidvalid'] = $uidvalid; return; } elseif (!is_null($uidvalid) && $ptr['d']['uidvalid'] != $uidvalid) { $this->_deleteMailbox($mailbox); } else { return; } } $this->_slicemap[$mailbox] = array('c' => 0, 'd' => array('uidvalid' => $uidvalid), 'i' => 0, 's' => array()); }
/** * Fetches a template from the specified file and return the parsed * contents. * * @param string $filename The file to fetch the template from. * * @return string The parsed template. */ public function fetch($filename = null) { $file = $this->_basepath . $filename; $force = $this->getOption('forcecompile'); if (!is_null($filename) && $file != $this->_templateFile) { $this->_template = $this->_templateFile = null; } /* First, check for a cached compiled version. */ $parts = array('horde_template', filemtime($file), $file); if ($this->getOption('gettext')) { $parts[] = setlocale(LC_ALL, 0); } $cacheid = implode('|', $parts); if (!$force && is_null($this->_template) && $this->_cache) { $this->_template = $this->_cache->get($cacheid, 0); if ($this->_template === false) { $this->_template = null; } } /* Parse and compile the template. */ if ($force || is_null($this->_template)) { $this->_template = str_replace("\n", " \n", file_get_contents($file)); $this->_parse(); if ($this->_cache) { $this->_cache->set($cacheid, $this->_template); if ($this->_logger) { $this->_logger->log(sprintf('Saved compiled template file for "%s".', $file), 'DEBUG'); } } } $this->_templateFile = $file; /* Template debugging. */ if ($this->getOption('debug')) { echo '<pre>' . htmlspecialchars($this->_template) . '</pre>'; } return $this->parse(); }
/** * TODO * * @param array $opts Options: * - 'file': (string) The filename to process. * REQUIRED for this driver. * - 'range': (array) The patchsets to process. * DEFAULT: None (all patchsets are processed). * - 'timezone': (string) The current timezone. * * @return Horde_Vcs_Patchset Patchset object. */ public function getPatchset($opts = array()) { $class = 'Horde_Vcs_Patchset_' . $this->_driver; if (!is_array($opts)) { $opts = array(); } ksort($opts); $cacheId = implode('|', array($class, $this->sourceroot, serialize($opts), $this->_cacheVersion)); if (!empty($this->_cache)) { if (isset($opts['file']) && file_exists($opts['file'])) { $ctime = time() - filemtime($opts['file']); } else { $ctime = 60; } if ($this->_cache->exists($cacheId, $ctime)) { return unserialize($this->_cache->get($cacheId, $ctime)); } } $ob = new $class($this, $opts); if (!empty($this->_cache)) { $this->_cache->set($cacheId, serialize($ob)); } return $ob; }
/** * Get cache value */ protected function _getCache($key, $thread = 0) { $key = $this->_getCacheKey($key, $thread); return $this->_cache->get($key, $GLOBALS['conf']['cache']['default_lifetime']); }
/** * Load application information from registry config files. */ protected function _loadApplications() { global $cli, $injector; if (!empty($this->_interfaces)) { return; } /* First, try to load from cache. */ if (!isset($cli) && !$this->isTest()) { if (Horde_Util::extensionExists('apc')) { $cstorage = 'Horde_Cache_Storage_Apc'; } elseif (Horde_Util::extensionExists('xcache')) { $cstorage = 'Horde_Cache_Storage_Xcache'; } else { $cstorage = 'Horde_Cache_Storage_File'; } $cache = new Horde_Cache(new $cstorage(array('no_gc' => true, 'prefix' => 'horde_registry_cache_')), array('lifetime' => 0, 'logger' => $injector->getInstance('Horde_Log_Logger'))); if (($cid = $this->_cacheId()) && ($cdata = $cache->get($cid, 0))) { try { list($this->applications, $this->_interfaces) = $injector->getInstance('Horde_Pack')->unpack($cdata); return; } catch (Horde_Pack_Exception $e) { } } } $config = new Horde_Registry_Registryconfig($this); $this->applications = $config->applications; $this->_interfaces = $config->interfaces; if (!isset($cache)) { return; } /* Need to determine hash of generated data, since it is possible that * there is dynamic data in the config files. This only needs to * be done once per session. */ $packed_data = $injector->getInstance('Horde_Pack')->pack(array($this->applications, $this->_interfaces)); $cid = $this->_cacheId($packed_data); if (!$cache->exists($cid, 0)) { $cache->set($cid, $packed_data); } }
/** * Reads values from the cache handler. * * The key is automatically prefixed to avoid collisions when using * different adapters or different configurations. * * @since Horde_Db 2.1.0 * * @param string $key A cache key. * * @return string A value. */ public function cacheRead($key) { return $this->_cache->get($this->_cacheKey($key), 0); }
/** * Retrieve list data. * * @param string $list_id ID of the connection matching the list. * * @return string The data of the object. */ public function loadList($list_id) { return $this->horde_cache->get($list_id, 0); }