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; }
/** * Should handle execution of the task, taking as much (optional) parameters as needed * * The parameters should be optional and failing to provide them should be handled by * the task */ public function execute($text = null) { if ($this->cache instanceof \Zend_Cache_Core) { $this->cache->clean(\Zend_Cache::CLEANING_MODE_ALL); $this->getBatch()->addMessage($this->_('Cache cleaned')); } }
/** * @group ZF-9092 */ public function testSettingLifetimeAsEmptyIsInterpretedAsNull() { $config = new Zend_Config(array('lifetime' => '', 'caching' => true)); $test = new Zend_Cache_Core(); $test->setConfig($config); $this->assertSame(NULL, $test->getOption('lifetime')); }
/** * 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; }
private function _getSecondLevelCache() { if (!$this->_secondLevelCache) { $c = new Zend_Cache_Core(array('lifetime' => null, 'write_control' => false, 'automatic_cleaning_factor' => 0, 'automatic_serialization' => true)); $c->setBackend(new Kwf_Cache_Backend_File(array('cache_dir' => 'cache/mediameta', 'hashed_directory_level' => 2))); $this->_secondLevelCache = $c; } return $this->_secondLevelCache; }
private static function _getCache() { static $cache; if (!isset($cache)) { $cache = new Zend_Cache_Core(array('lifetime' => null, 'write_control' => false, 'automatic_cleaning_factor' => 0, 'automatic_serialization' => true)); $cache->setBackend(new Kwf_Cache_Backend_File(array('cache_dir' => 'cache/commonjs', 'hashed_directory_level' => 2))); } return $cache; }
/** * 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 static function _getSlowCache() { static $ret; if (!isset($ret)) { $ret = new Zend_Cache_Core(array('lifetime' => null, 'automatic_serialization' => true, 'automatic_cleaning_factor' => 0, 'write_control' => false)); $ret->setBackend(new Zend_Cache_Backend_File(array('cache_dir' => 'cache/assets', 'cache_file_perm' => 0666, 'hashed_directory_perm' => 0777, 'hashed_directory_level' => 2))); } return $ret; }
public function testTouch() { $this->rediska->set('test', array('aaa', time(), 100)); $this->rediska->expire('test', 100); $reply = $this->cache->touch('test', 200); $this->assertTrue($reply); $lifetime = $this->rediska->getLifetime('test'); $this->assertTrue($lifetime > 290); $values = $this->rediska->get('test'); $this->assertEquals(300, $values[2]); }
/** * */ 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; }
/** * Remove cache matching id, prefix or tags * @param string $cacheId cache id to remove * @param string $cachePrefix cache prefix to remove * @param array $tags array of cache tags to remove */ public function clean($cacheId = '', $cachePrefix = '', $tags = array()) { $tags = $this->_sanitizeTags($tags); $this->_cache->clean(Zend_Cache::CLEANING_MODE_OLD); if (!$cachePrefix && !$cacheId) { if (is_array($tags) && !empty($tags)) { $this->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags); } else { $this->_cache->clean(Zend_Cache::CLEANING_MODE_ALL); } } else { $cacheId = $this->_makeCacheId($cacheId, $cachePrefix); $this->_cache->remove($cacheId); } }
/** * Redis support * * @return Redis | null */ public function getRedisAdapter() { if (isset($this->cacheAdapter) && get_class($this->cacheAdapter) == Redis::class) { return $this->cacheAdapter->getAdapter(); } return null; }
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; }
/** * Overrule this function for any activities you want to take place * after the form has successfully been validated, but before any * buttons are processed. * * @param int $step The current step */ protected function afterFormValidationFor($step) { if (3 == $step) { $import = $this->loadImportData(); $model = $this->getModel(); $saves = array(); foreach ($model->getCol('exportCode') as $name => $exportCode) { if (isset($this->formData[$name]) && $this->formData[$name]) { $saves[] = array('gsu_id_survey' => $this->formData[$name], 'gsu_export_code' => $exportCode); $import['surveyCodes'][$exportCode] = $this->formData[$name]; } } if ($saves) { $sModel = new \MUtil_Model_TableModel('gems__surveys'); \Gems_Model::setChangeFieldsByPrefix($sModel, 'gus', $this->currentUser->getUserId()); $sModel->saveAll($saves); $count = $sModel->getChanged(); if ($count == 0) { $this->addMessage($this->_('No export code changed')); } else { $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('surveys')); $this->addMessage(sprintf($this->plural('%d export code changed', '%d export codes changed', $count), $count)); } } } }
/** * 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; }
/** * 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; }
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')); }
/** * 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; }
/** * Clean cached data by specific tag * * @return bool */ public function flush() { Magento_Profiler::start('cache_flush', $this->_generateProfilerTags('flush')); $res = $this->_frontend->clean(); Magento_Profiler::stop('cache_flush'); return $res; }
/** * 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; }
/** * Empty the cache of the organization * * @return \Gems_User_Organization (continutation pattern) */ public function invalidateCache() { if ($this->cache) { $cacheId = $this->_getCacheId(); $this->cache->remove($cacheId); } return $this; }
/** * 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'); } } }
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; }
/** * Overrule this function if you want to perform a different * action than deleting when the user choose 'yes'. */ protected function performAction() { $model = $this->getModel(); $model->save($this->saveData + $model->getFilter()); if ($this->cacheTags && $this->cache instanceof \Zend_Cache_Core) { $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array) $this->cacheTags); } $this->setAfterDeleteRoute(); }
/** * Constructor * * @param array $options associative array of options * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested */ public function __construct($options = array()) { if (isset($options['httpConditional'])) { if ($options['httpConditional']) { Zend_Cache::throwException('httpConditional is not implemented for the moment !'); } } parent::__construct($options); }
/** * Hook that allows actions when data was saved * * When not rerouted, the form will be populated afterwards * * @param int $changed The number of changed rows (0 or 1 usually, but can be more) */ protected function afterSave($changed) { if ($changed) { // Clean cache on changes if ($this->cacheTags && $this->cache instanceof \Zend_Cache_Core) { $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array) $this->cacheTags); } } }
/** * Hook that allows actions when data was saved * * When not rerouted, the form will be populated afterwards * * @param int $changed The number of changed rows (0 or 1 usually, but can be more) */ protected function afterSave($changed) { if ($this->trackEngine) { $this->addMessage($this->_('Track merge finished')); } else { $this->addMessage($this->_('Track import finished')); } $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('tracks')); }
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; } } }