/** * Load value from swap file. * * @internal * @param \Zend\Memory\Container\Movable $container * @param integer $id */ public function load(Container\Movable $container, $id) { $value = $this->_cache->getItem($this->_managerId . $id, array('ttl' => 0)); // Try to swap other objects if necessary // (do not include specified object into check) $this->_memorySize += strlen($value); $this->_swapCheck(); // Add loaded obect to the end of loaded objects list $container->setValue($value); if ($this->_sizes[$id] > $this->_minSize) { // Add object to the end of "unload candidates list" $this->_unloadCandidates[$id] = $container; } }
/** * Returns the page item cache. * * @return array */ public function getPageItemCache() { $data = array(); if ($this->_cacheEnabled()) { $cacheIds = self::$_cache->find(CacheAdapter::MATCH_TAGS_OR, array('tags' => array($this->_getCacheInternalId()))); $cacheIds = array(); while (($item = self::$_cache->fetch()) !== false) { $cacheIds[] = $item['key']; } foreach ($cacheIds as $id) { if (preg_match('|' . self::CACHE_TAG_PREFIX . "(\\d+)_.*|", $id, $page)) { $data[$page[1]] = self::$_cache->getItem($this->_getCacheId($page[1])); } } } return $data; }
/** * Recupera um item do cache, identificado pela chave * * @access public * @param string $key Chave de identificação do item do cache * @return mixed|null Item carregado do cache, ou NULL caso o item não exista */ public function getItem(string $key) { return $this->adapter->getItem($key); }
public function testTouchInitialValueIfIgnoreMissingItemsEnabled() { $this->_options->setIgnoreMissingItems(true); $this->_storage->touchItem('newkey'); $this->assertEquals('', $this->_storage->getItem('newkey')); }
/** * Internal function for adding translation data * * This may be a new language or additional data for an existing language * If the options 'clear' is true, then the translation data for the specified * language is replaced and added otherwise * * @see Zend_Locale * @param array|\Zend\Config $content Translation data to add * @throws \Zend\Translator\Exception\InvalidArgumentException * @return \Zend\Translator\Adapter\AbstractAdapter Provides fluent interface */ private function _addTranslationData($options = array()) { if ($options instanceof Config) { $options = $options->toArray(); } else { if (func_num_args() > 1) { $args = func_get_args(); $options['content'] = array_shift($args); if (!empty($args)) { $options['locale'] = array_shift($args); } if (!empty($args)) { $options += array_shift($args); } } } if ($options['content'] instanceof Translator\Translator || $options['content'] instanceof AbstractAdapter) { $options['usetranslateadapter'] = true; $content = $options['content']; if (empty($options['locale']) || $options['locale'] == 'auto') { $locales = $content->getList(); } else { $locales = array(1 => $options['locale']); } foreach ($locales as $locale) { $options['locale'] = $locale; $options['content'] = $content->getMessages($locale); $this->_addTranslationData($options); } return $this; } try { $options['locale'] = Locale\Locale::findLocale($options['locale']); } catch (Locale\Exception $e) { throw new Exception\InvalidArgumentException("The given Language '{$locale}' does not exist", 0, $e); } if ($options['clear'] || !isset($this->_translate[$options['locale']])) { $this->_translate[$options['locale']] = array(); } $read = true; if (isset(self::$_cache)) { $id = 'Zend_Translator_' . md5(serialize($options['content'])) . '_' . $this->toString(); $temp = self::$_cache->getItem($id); if ($temp) { $read = false; } } if ($options['reload']) { $read = true; } if ($read) { if (!empty($options['usetranslateadapter'])) { $temp = array($options['locale'] => $options['content']); } else { $temp = $this->_loadTranslationData($options['content'], $options['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 Locale\Locale($options['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_Translator_' . md5(serialize($options['content'])) . '_' . $this->toString(); $this->saveCache($temp, $id); } return $this; }
/** * Initializes metadata. * * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata * information. Returns true if and only if the metadata are loaded from cache. * * @return boolean * @throws \Zend\Db\Table\Exception */ protected function _setupMetadata() { if ($this->metadataCacheInClass() && count($this->_metadata) > 0) { return true; } // Assume that metadata will be loaded from cache $isMetadataFromCache = true; // If $this has no metadata cache but the class has a default metadata cache if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) { // Make $this use the default metadata cache of the class $this->_setMetadataCache(self::$_defaultMetadataCache); } // If $this has a metadata cache if (null !== $this->_metadataCache) { $cacheId = $this->_cacheId(); } // If $this has no metadata cache or metadata cache misses if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->getItem($cacheId))) { // Metadata are not loaded from cache $isMetadataFromCache = false; // Fetch metadata from the adapter's describeTable() method $metadata = $this->_db->describeTable($this->_name, $this->_schema); // If $this has a metadata cache, then cache the metadata if (null !== $this->_metadataCache && !$this->_metadataCache->setItem($cacheId, $metadata)) { trigger_error('Failed saving metadata to metadataCache', E_USER_NOTICE); } } // Assign the metadata to $this $this->_metadata = $metadata; // Return whether the metadata were loaded from cache return $isMetadataFromCache; }
/** * Initializes metadata. * * If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata * information. Returns true if and only if the metadata are loaded from cache. * * @return boolean * @throws \Zend\Db\Table\Exception */ protected function _setupMetadata() { if ($this->metadataCacheInClass() && count($this->_metadata) > 0) { return true; } // Assume that metadata will be loaded from cache $isMetadataFromCache = true; // If $this has no metadata cache but the class has a default metadata cache if (null === $this->_metadataCache && null !== self::$_defaultMetadataCache) { // Make $this use the default metadata cache of the class $this->_setMetadataCache(self::$_defaultMetadataCache); } // If $this has a metadata cache if (null !== $this->_metadataCache) { // Define the cache identifier where the metadata are saved //get db configuration $dbConfig = $this->_db->getConfig(); // Define the cache identifier where the metadata are saved $cacheId = md5((isset($dbConfig['options']['port']) ? ':' . $dbConfig['options']['port'] : null) . (isset($dbConfig['options']['host']) ? ':' . $dbConfig['options']['host'] : null) . '/' . $dbConfig['dbname'] . ':' . $this->_schema . '.' . $this->_name); } // If $this has no metadata cache or metadata cache misses if (null === $this->_metadataCache || !($metadata = $this->_metadataCache->getItem($cacheId))) { // Metadata are not loaded from cache $isMetadataFromCache = false; // Fetch metadata from the adapter's describeTable() method $metadata = $this->_db->describeTable($this->_name, $this->_schema); // If $this has a metadata cache, then cache the metadata if (null !== $this->_metadataCache && !$this->_metadataCache->setItem($cacheId, $metadata)) { trigger_error('Failed saving metadata to metadataCache', E_USER_NOTICE); } } // Assign the metadata to $this $this->_metadata = $metadata; // Return whether the metadata were loaded from cache return $isMetadataFromCache; }