public static function find($search_data, array $overrideSources = null) { $sources = array('local', 'def'); if (is_array($overrideSources)) { $sources = $overrideSources; } if (self::$_cache !== null && is_scalar($search_data) && is_numeric($search_data)) { $cached = self::$_cache->load(__CLASS__ . implode('_', $sources) . $search_data); if ($cached !== false) { return $cached; } } $found = array(); foreach ($sources as $source) { $sourceObject = self::getSource($source); $founded_temp = self::findInSource($search_data, is_array($search_data) ? self::detectCustomerType($search_data) : '', $sourceObject); if (count($founded_temp) > 0) { $found = array_merge($found, $founded_temp); } } if (self::$_cache !== null && is_scalar($search_data) && count($found) == 1 && is_numeric($search_data)) { self::$_cache->save($found, __CLASS__ . implode('_', $sources) . $search_data); } return $found; }
/** * Pre event - try load content from cache * * @param \Zend_EventManager_EventDescription $event * @return mixed */ public function load(\Zend_EventManager_EventDescription $event) { if (false !== ($content = $this->cache->load($this->_getIdentifier($event)))) { $event->stopPropagation(true); return $content; } }
/** * Recupera parser do Pdf: faz o parser em tempo real ou recupera do cache * * @param string $arqInsert * @return fpdi_pdf_parser */ public function cacheOrParserPdfWithFPDI($pagePdf, $pathArquivoPdf) { //try { //verifica parser do Pdf no cache $parserPdfCache = $this->cache->load($pagePdf); $origem = "--->parserPdf vem do cache---"; $this->objMakePdf->current_filename = $pathArquivoPdf; //recupera do cache if ($parserPdfCache == false) { //tento fazer o parser do pdf $parserPdfCache = $this->objMakePdf->_getPdfParser($pathArquivoPdf); //salvo o parser do pdf no cache $this->cache->save($parserPdfCache, $pagePdf); $origem = "--->parserPdf NAO vem do cache---"; } else { //grava parser pdf no var do objeto FPDI $this->objMakePdf->parsers[$pathArquivoPdf] = $parserPdfCache; } echo $origem; $this->setCacheYesOrNo($origem); $result = true; //} catch (Exception $e) { // throw new Exception("There is a problem at PDF parser process"); // $result = false; // } return $result; }
/** * @group all */ public function testClean() { $this->setKeys(); $reply = $this->cache->clean(); $this->assertTrue($reply); $reply = $this->cache->load('test_aaa'); $this->assertFalse($reply); }
public function testLoad() { $this->rediska->set('test', array('aaa', time(), null)); $value = $this->cache->load('test'); $this->assertEquals('aaa', $value); $value = $this->cache->load('test2'); $this->assertFalse($value); }
/** * Load data from cache * @param $cacheKey Unique cache id * @param string $cachePrefix Cache prefix * @return null Returns null if nothing found */ public function load($cacheKey, $cachePrefix = '') { $cacheId = $this->_makeCacheId($cacheKey, $cachePrefix); if (!$this->_cache->test($cacheId)) { return null; } return $this->_cache->load($cacheId); }
/** * * @param string $id A unique name identifying the batch */ public function __construct($id, \Zend_Cache_Core $cache) { $this->_cacheId = 'batch_' . session_id() . '_' . $id; $this->_cache = $cache; $this->_commands = $this->_cache->load($this->_cacheId, true); if (!$this->_commands) { $this->_commands = array(); } }
/** * */ public function alternative($alternative_id, Model_Alternative $modelAlternative) { $nameCache = 'alternative_' . $alternative_id; $alternative = $this->cache->load($nameCache); $origem = "--->alternative vem do cache---"; //recupera do cache if ($alternative == false) { $alternative = $modelAlternative->getAlternativeById($alternative_id); $this->cache->save($alternative, $nameCache); $origem = "--->alternative NAO vem do cache---"; } return $alternative; }
/** * metodo chamado em Vtx_Plugin_Permission */ public function fazCacheAcl($sysId = 1) { if ($sysId == 1) { $nameCache = 'acl'; } else { $nameCache = 'acl' . $sysId; } $acl = $this->cache->load($nameCache); if (!$acl) { $acl = new Model_Acl(true); $this->cache->save($acl, $nameCache); } return $acl; }
/** * Generates the adapter * * @param string|array $data Translation data or filename for this adapter * @param string|Zend_Locale $locale (optional) Locale/Language to set, identical with Locale * identifiers see Zend_Locale for more information * @param array $options (optional) Options for the adaptor * @throws Zend_Translate_Exception * @return void */ public function __construct($data, $locale = null, array $options = array()) { if (isset(self::$_cache)) { $id = 'Zend_Translate_' . $this->toString(); if ($result = self::$_cache->load($id)) { $this->_translate = unserialize($result); $this->_options = $this->_translate['_options_']; unset($this->_translate['_options_']); return; } } $this->addTranslation($data, $locale, $options); $this->_automatic = true; }
/** * Read session data * * @param string $id */ public function read($id) { // The cache backend might produce some error if the servers are unavailable // for example. $oldStartError = Zend_Session_Exception::$sessionStartError; // Fetch the contents from the cache $session = $this->_cache->load($this->_prefix . $id); if (!$session) { $session = ''; } // Restore the previous error (if any) Zend_Session_Exception::$sessionStartError = $oldStartError; return $session; }
public function getHistorical($name, $date) { $sufix = str_replace('-', '', substr($date, 0, 10)); $cached = $this->_cache->load(__CLASS__ . $name . $sufix); if ($cached !== false) { return $cached; } else { $row = $this->fetchRow(array('key = ?' => $name, 'created_at::date <= \'' . $date . '\'::date'), 'id DESC'); if ($row !== null) { $this->_cache->save($row->value, __CLASS__ . $name . $sufix); return $row->value; } else { return $this->get($name); } } }
protected function _loadConfig($file) { if ($this->_useCache == false) { return parent::_loadConfig($file); } $configMTime = filemtime($file); $cacheId = "application_conf_" . md5($file . $this->getEnvironment()); $cacheLastMTime = $this->_configCache->test($cacheId); //Valid cache? if ($cacheLastMTime !== false && $configMTime <= $cacheLastMTime) { return $this->_configCache->load($cacheId, true); } $config = parent::_loadConfig($file); $this->_configCache->save($config, $cacheId, array(), null); return $config; }
/** * Get cache object * * @param string $id * @return Zend_Cache_Core|mixed */ public function getCache($id = null) { if ($id !== null) { return $this->_cache->load($id); } return $this->_cache; }
/** * get by id * - results are cached * * @param string $_id the id of the peer * @return Voipmanager_Model_Snom_Location */ public function get($_id) { $id = Tinebase_Record_Abstract::convertId($_id, $this->_modelName); if ($this->_cacheIdPrefix && $this->_cache) { $cacheId = $this->_cacheIdPrefix . $id; if ($this->_cache->test($id)) { $result = $this->_cache->load($id); } else { $result = $this->_backend->get($id); $this->_cache->save($result, $cacheId, array($this->_cacheIdPrefix), 5); } } else { $result = $this->_backend->get($id); } return $result; }
/** * Replace one found esi include with a given url * * @param string $url * @return string|null */ protected function _replaceEsiInclude($url) { $uri = 'http://' . $_SERVER['HTTP_HOST'] . $url; $key = $this->_getCacheId($uri); if ($this->_cacheEnabled()) { // detect if url is cached $data = self::$_cache->load($key); if (false !== $data) { return $data; } } $fp = fopen($uri, 'r', false, $this->_getHttpContext()); if (false !== $fp) { $data = stream_get_contents($fp); if ($this->_cacheEnabled()) { $meta = stream_get_meta_data($fp); // fetch the metadata of the fopen call foreach ($meta['wrapper_data'] as $header) { $match = array(); if (preg_match(self::ESI_CACHE_REGEX, $header, $match)) { if (false !== $data) { // cache url with the respected max-age setting self::$_cache->save($data, $key, array(), intval($match[1])); break; } } } } fclose($fp); return $data; } return null; }
/** * * @param string $key * @return Engine_Package_Manager_Operation_Abstract */ public function __get($key) { // Doesn't exist if (!in_array($key, $this->_keys)) { return null; } // Exists in memory if ($this->_loaded[$key]) { $value = $this->_data[$key]; // Write to disk if caching if ($this->_caching) { $this->_cache->save($value, $this->_getCacheKey($key), array($this->_id)); $this->_data[$key] = null; $this->_loaded[$key] = false; } } else { $value = $this->_cache->load($this->_getCacheKey($key)); // Write to memory if not caching if (!$this->_caching) { $this->_data[$key] = $value; $this->_loaded[$key] = true; } } return $value; }
/** * Load data from cache by id * * @param string $id * @return string */ public function load($id) { Magento_Profiler::start('cache_load', $this->_generateProfilerTags('load')); $result = $this->_frontend->load($this->_id($id)); Magento_Profiler::stop('cache_load'); return $result; }
/** * Perform a raw query against the search index, returning a SolrResultSet object that * can be used to extract a more complete result set * * @param String $query * The lucene query to execute. * @param int $page * What result page are we on? * @param int $limit * How many items to limit the query to return * @param array $params * A set of parameters to be passed along with the query * @param array $andWith * A set of extra and with terms to add to the query * @return SolrResultSet */ public function query($query, $offset = 0, $limit = 20, $params = array(), $andWith = array()) { if (is_string($query)) { $builder = $this->getQueryBuilder('default'); $builder->baseQuery($query); $query = $builder; } // be very specific about the subsite support :). if (ClassInfo::exists('Subsite')) { $query->andWith('SubsiteID_i', Subsite::currentSubsiteID()); } // add the stage details in - we should probably use an extension mechanism for this, // but for now this will have to do. @TODO Refactor this.... $stage = Versioned::current_stage(); if (!$stage && !(isset($params['ignore_stage']) && $params['ignore_stage'])) { // default to searching live content only $stage = 'Live'; } if (!isset($params['ignore_stage']) || !$params['ignore_stage']) { $query->andWith('SS_Stage_ms', $stage); } if ($andWith) { foreach ($andWith as $field => $value) { $query->andWith($field, $value); } } $extraParams = $query->getParams(); $params = array_merge($params, $extraParams); $query = $query->toString(); $response = null; $rawResponse = null; $solr = $this->getSolr(); $key = null; if ($this->cache) { $key = md5($query . $offset . $limit . serialize($params)); if ($rawResponse = $this->cache->load($key)) { $response = new Apache_Solr_Response($rawResponse, array('HTTP/1.1 200 OK', 'Content-Type: text/plain; charset=utf-8'), $solr->getCreateDocuments(), $solr->getCollapseSingleValueArrays()); } } if (!$response) { // Execute the query and log any errors on failure, always displaying the search results to the user. if ($this->isConnected()) { try { $response = $this->getSolr()->search($query, $offset, $limit, $params); } catch (Exception $e) { SS_Log::log($e, SS_Log::NOTICE); } } } $queryParams = new stdClass(); $queryParams->offset = $offset; $queryParams->limit = $limit; $queryParams->params = $params; $results = new SolrResultSet($query, $response, $queryParams, $this); if ($this->cache && !$rawResponse && $key && $response) { $this->cache->save($response->getRawResponse(), $key, array(), $this->cacheTime); } return $results; }
/** * Fetch an entry from cache * * @param string $key * @return mixed|NULL */ public function load($key) { if (null !== $this->cacheAdapter) { $prefixedKey = $this->prefixKey($key); return $this->cacheAdapter->load($prefixedKey); } return null; }
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) { if (!$this->_options['caching']) { return false; } $data = parent::load($id, $doNotTestCacheValidity, $doNotUnserialize); Centurion_Cache_TagManager::start($id, $this, $data, false); return $data; }
/** * Test if a cache is available for the given id and (if yes) return it (false else) * * @param string $id cache id * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested * @param boolean $doNotUnserialize do not serialize (even if automatic_serialization is true) => for internal use * @return mixed cached datas (or false) */ public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false) { if (!$doNotTestCacheValidity) { if ($this->test($id)) { return parent::load($id, true, $doNotUnserialize); } return false; } return parent::load($id, true, $doNotUnserialize); }
public static function loadSchemaFromDb(Zend_Db_Adapter_Abstract $db, Zend_Cache_Core $cache) { static $tables = array(); if (empty($tables)) { if (!($tables = $cache->load('tables'))) { $tables = $db->listTables(); $cache->save($tables, 'tables'); } } foreach ($tables as $table) { if (!isset(self::$schema[$table])) { if (!($tableStructure = $cache->load('tables_' . $table))) { $tableStructure = $db->describeTable($table); $cache->save($tableStructure, 'tables_' . $table); } self::$schema[$table] = $tableStructure; } } }
/** * Récupère l'instance du singleton en gèrant la persistance * * @param bool $clearCache détruit le cache auparavant * @return Cache_Acl */ public static function getInstance($clearCache = false) { if (static::$_cache) { if ($clearCache) { static::$_cache->remove(self::CACHE_KEY); } if (false === (static::$_instance = static::$_cache->load(self::CACHE_KEY))) { if (static::$_instance == null) { static::$_instance = new static(); } static::$_cache->save(static::$_instance, self::CACHE_KEY); } } else { if (static::$_instance == null) { static::$_instance = new static(); } } return static::$_instance; }
/** * Internal function for adding translation data * * It may be a new language or additional data for existing language * If $clear parameter is true, then translation data for specified * language is replaced and added otherwise * * @see Zend_Locale * @param array|string $data Translation data * @param string|Zend_Locale $locale Locale/Language to add data for, identical with locale identifier, * @see Zend_Locale for more information * @param array $options (optional) Option for this Adapter * @throws Zend_Translate_Exception * @return Zend_Translate_Adapter Provides fluent interface */ private function _addTranslationData($data, $locale, array $options = array()) { try { $locale = Zend_Locale::findLocale($locale); } catch (Zend_Locale_Exception $e) { require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist", 0, $e); } if ($options['clear'] || !isset($this->_translate[$locale])) { $this->_translate[$locale] = array(); } $read = true; if (isset(self::$_cache)) { $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString(); $temp = self::$_cache->load($id); if ($temp) { $read = false; } } if ($options['reload']) { $read = true; } if ($read) { $temp = $this->_loadTranslationData($data, $locale, $options); } if (empty($temp)) { $temp = array(); } $keys = array_keys($temp); foreach ($keys as $key) { if (!isset($this->_translate[$key])) { $this->_translate[$key] = array(); } if (array_key_exists($key, $temp) && is_array($temp[$key])) { $this->_translate[$key] = $temp[$key] + $this->_translate[$key]; } } if ($this->_automatic === true) { $find = new Zend_Locale($locale); $browser = $find->getEnvironment() + $find->getBrowser(); arsort($browser); foreach ($browser as $language => $quality) { if (isset($this->_translate[$language])) { $this->_options['locale'] = $language; break; } } } if ($read and isset(self::$_cache)) { $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString(); self::$_cache->save($temp, $id, array('Zend_Translate')); } return $this; }
/** * 取得缓存中的权限关系数据 * * @return array */ protected function _getAclsInCache() { if (null === self::$_cache) { throw new ZtChart_Model_Acl_Loader_Exception('The cache for acl is not exist.'); } if (false === ($acl = self::$_cache->load('acl'))) { if (!self::$_cache->save($acl = $this->_getAclsInDb(), 'acl')) { throw new ZtChart_Model_Acl_Loader_Exception('The cache for acl cannot save data.'); } } return $acl; }
/** * Returns the page item cache. * * @return array */ public function getPageItemCache() { $data = array(); if ($this->_cacheEnabled()) { foreach (self::$_cache->getIdsMatchingTags(array($this->_getCacheInternalId())) as $id) { if (preg_match('|' . self::CACHE_TAG_PREFIX . "(\\d+)_.*|", $id, $page)) { $data[$page[1]] = self::$_cache->load($this->_getCacheId($page[1])); } } } return $data; }
/** * @return Engine_Package_Manager_Transaction */ protected function _loadTransaction() { $id = $this->_session->transactionIdentity; if (!$id) { throw new Engine_Exception('No transaction id is stored in the session.'); } $transaction = $this->_cache->load('transaction' . $id); if (!$transaction || !$transaction instanceof Engine_Package_Manager_Transaction) { throw new Engine_Exception('No transaction was found in the cache.'); } $transaction->setManager($this->_packageManager); return $transaction; }
/** * @param $key * @return mixed */ protected static function loadFromCache($key) { if (self::$_cache instanceof Zend_Cache_Core) { $val = self::$_cache->load($key); if ($val === false) { return null; } else { return $val; } } else { return null; } }
/** * Метод загружающий и устанавливающий * при налачии объект Zend_Acl из кэша (Cache) * Возвращает true вслучае успешной загрузки * и false вслучае неудачи * * @return bool */ protected function _loadCache() { if (!$this->_cache) { return false; } $cache = $this->_cache->load($this->_cacheId); if ($cache) { $this->_acl = $cache; return true; } else { return false; } }