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; }
/** * Save the cache here */ public function __destruct() { // \MUtil_Echo::track(count($this->_commands)); if ($this->_commands) { $this->_cache->save($this->_commands, $this->_cacheId, array('batch', 'sess_' . session_id())); } else { $this->_cache->remove($this->_cacheId); } }
/** * */ 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; }
public function testSave() { $reply = $this->cache->save('aaa', 'test'); $this->assertTrue($reply); $value = $this->rediska->get('test'); $this->assertTrue(is_array($value)); $this->assertEquals('aaa', $value[0]); $reply = $this->cache->save('aaa', 'test', array(), 2); $this->assertTrue($reply); sleep(3); $value = $this->rediska->get('test'); $this->assertNull($value); }
/** * 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; }
/** * 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; }
/** * 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 a fluid interface */ private function _addTranslationData($data, $locale, array $options = array()) { if (!($locale = Zend_Locale::isLocale($locale))) { /** * @see Zend_Translate_Exception */ require_once 'Zend/Translate/Exception.php'; throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist"); } if (!array_key_exists($locale, $this->_translate)) { $this->_translate[$locale] = array(); } $this->_loadTranslationData($data, $locale, $options); if ($this->_automatic === true) { $find = new Zend_Locale($locale); $browser = $find->getBrowser() + $find->getEnvironment(); arsort($browser); foreach ($browser as $language => $quality) { if (array_key_exists($language, $this->_translate)) { $this->_options['locale'] = $language; break; } } } if (isset(self::$_cache)) { $id = 'Zend_Translate_' . $this->toString(); $temp = $this->_translate; $temp['_options_'] = $this->_options; self::$_cache->save(serialize($temp), $id); } return $this; }
protected function setKeys() { $this->cache->save('aaa', 'test_aaa', array('tag_a1')); $this->cache->save('bbb', 'test_bbb', array('tag_a1', 'tag_a2')); $this->cache->save('ccc', 'test_ccc', array('tag_a2')); $this->cache->save('ddd', 'test_ddd', array('tag_a3')); }
/** * 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; }
/** * 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; }
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; }
/** * Save in cache * * @return void */ private function _saveInCache(Zend_Cache_Core $cache) { $cacheData = array(); $cacheData['tableName'] = $this->_dbData->getTable()->getComponentName(); $cacheData['dataArray'] = $this->_dbData->toArray(self::SERIALIZATION_DEEP); $cache->save($cacheData, $this->_cacheKey); }
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); } } }
/** * Utility function for loading a query from cache * * @param string $cacheId The class is prepended to this id * @param mixed $sql string or \Zend_Db_Select * @param callable $function The function called with each row to form the result * @param string $keyField The field containing the key for each row * @param mixed $tags string or array of strings * @param string Optional function to sort on, only known functions will do * @return array */ protected function _getSelectProcessedCached($cacheId, $sql, $function, $keyField, $tags = array(), $sort = null) { $cacheId = get_class($this) . '_' . $cacheId; $result = false; //$this->cache->load($cacheId); if ($result) { return $result; } $result = array(); try { $rows = $this->db->fetchAll($sql); if ($rows) { foreach ($rows as $row) { if (!isset($result[$row[$keyField]])) { $result[$row[$keyField]] = call_user_func($function, $row); } } if ($sort) { $this->_sortResult($result, $sort); } } $this->cache->save($result, $cacheId, (array) $tags); } catch (\Zend_Db_Statement_Mysqli_Exception $e) { } 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; }
/** * Save some data in a cache * * @param mixed $data Data to put in cache (can be another type than string if * automatic_serialization is on) * @param null|string $cacheId Cache id (if not set, the last cache id will be used) * @param string[] $tags Cache tags * @param bool|int $specificLifetime If != false, set a specific lifetime for this cache record * (null => infinite lifetime) * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by * some particular backends * @return bool True if no problem */ public function save($data, $cacheId = null, $tags = [], $specificLifetime = false, $priority = 8) { if ($this->getOption('disable_save')) { return true; } $tags = $this->_tags($tags); return parent::save($data, $cacheId, $tags, $specificLifetime, $priority); }
/** * Post event - save content in cache * * @param \Zend_EventManager_EventDescription $event */ public function save(\Zend_EventManager_EventDescription $event) { $params = $event->getParams(); if (!isset($params['data'])) { throw new \Zend_EventManager_Exception_InvalidArgumentException('Missing param data.'); } $this->cache->save($params['data'], $this->_getIdentifier($event), $this->_getTags($event)); }
public function deny($roles = null, $resources = null, $privileges = null, Zend_Acl_Assert_Interface $assert = null) { $return = parent::deny($roles, $resources, $privileges, $assert); if (static::$_cache) { static::$_cache->save($this, self::CACHE_KEY); } return $return; }
/** * Write Session - commit data to resource * * @param string $id * @param mixed $data */ public function write($id, $data) { try { return $this->_cache->save($data, $this->_prefix . $id, array(), $this->_maxLifeTime); } catch (Exception $e) { App::log()->crit($e); } }
/** * Save to cache * * @throws \Gems_Exception */ private function _save() { if ($this->_cache instanceof \Zend_Cache_Core) { if (!($this->_cache->save($this->_acl, $this->_cacheid, array('roles'), null) && $this->_cache->save($this->_roleTranslations, $this->_cacheid . 'trans', array('roles'), null))) { throw new \Gems_Exception('Failed to save acl to cache'); } } }
/** * Writes an entry to cache * * @param mixed $data * @param string $key * @param bool|int|null $lifeTime false or 0 means default value, null means maximum lifetime * @return boolean */ public function save($data, $key, $lifeTime = 0) { if (null !== $this->cacheAdapter) { $this->logMessage('Saved key ' . $key . ' with size ' . sizeof($data) . ' and lifetime of ' . $lifeTime); $prefixedKey = $this->prefixKey($key); return $this->cacheAdapter->save($data, $prefixedKey, array(), $lifeTime); } return false; }
/** * Save data * * @param string $data * @param string $id * @param array $tags * @param int $lifeTime * @return bool */ public function save($data, $id, $tags = array(), $lifeTime = null) { /** * Add global magento cache tag to all cached data exclude config cache */ if (!in_array(Mage_Core_Model_Config::CACHE_TAG, $tags)) { $tags[] = Mage_Core_Model_App::CACHE_TAG; } return $this->_frontend->save((string) $data, $this->_id($id), $this->_tags($tags), $lifeTime); }
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; } } }
/** * Invalid cache * * @return void */ public function testShouldReturnFalseWithInvalidCache() { if (!is_writeable(dirname(__FILE__))) { $this->markTestIncomplete('Directory no writable'); } $this->_cache->save('asdf', 'cache'); $server = new Zend_XmlRpc_Server(); $this->assertFalse(Zym_XmlRpc_Server_Cache::get('cache', $this->_cache, $server)); $server = new Zend_XmlRpc_Server(); $this->assertFalse(Zym_XmlRpc_Server_Cache::get('fakeId', $this->_cache, $server)); }
/** * 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; }
public static function appendSiteinfo($suffix, $siteinfo) { $key = self::CACHE_TAG_PREFIX . $suffix; if (array_key_exists($key, self::$_siteinfokeys)) { // require_once 'Diggin/Scraper/Helper/Simplexml/Exception.php'; throw new \Diggin\Scraper\Helper\Simplexml\Exception("{$key} is already used."); } if (!self::getSiteinfo($key)) { self::$_cache->save($siteinfo, $key); } array_push(self::$_siteinfokeys, $key); }
/** * Cache a file containing the dispatch list. * * Serializes the XMLRPC server callbacks array and stores the information * in Zend_Cache_Core * * @param string $id * @param Zend_Cache_Core $coreCache * @param Zend_XmlRpc_Server $server * @return bool */ public static function save($id, Zend_Cache_Core $coreCache, Zend_XmlRpc_Server $server) { // Get function list $methods = $server->getFunctions(); // Remove system.* methods foreach ($methods as $name => $method) { if ($method->system) { unset($methods[$name]); } } // Store return (bool) $coreCache->save(serialize($methods), $id, array(), null); }
public function __set($key, $value) { if (!in_array($key, $this->_keys)) { $this->_keys[] = $key; } if (!$this->_caching) { $this->_data[$key] = $value; $this->_loaded[$key] = true; } else { $this->_data[$key] = null; $this->_loaded[$key] = false; $this->_cache->save($value, $this->_getCacheKey($key), array($this->_id)); } }
/** * Load data from cache or database */ protected function load() { if ($this->_cache !== null) { $cacheId = 'Shopware_Config'; if ($this->_shop !== null) { $cacheId .= '_' . $this->_shop->getId(); } if (($this->_data = $this->_cache->load($cacheId)) === false) { $this->_data = $this->readData(); $this->_cache->save($this->_data, $cacheId, $this->_cacheTags, $this->_cacheTime); } } else { $this->_data = $this->readData(); } }