/** * Generate WSDL content and save it to cache. * * @param array $requestedResources * @param string $endpointUrl * @return string * @throws Mage_Webapi_Exception */ public function handle($requestedResources, $endpointUrl) { /** Sort requested resources by names to prevent caching of the same wsdl file more than once. */ ksort($requestedResources); $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedResources)); if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) { $cachedWsdlContent = $this->_cache->load($cacheId); if ($cachedWsdlContent !== false) { return $cachedWsdlContent; } } $resources = array(); try { foreach ($requestedResources as $resourceName => $resourceVersion) { $resources[$resourceName] = $this->_apiConfig->getResourceDataMerged($resourceName, $resourceVersion); } } catch (Exception $e) { throw new Mage_Webapi_Exception($e->getMessage(), Mage_Webapi_Exception::HTTP_BAD_REQUEST); } $wsdlContent = $this->generate($resources, $endpointUrl); if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) { $this->_cache->save($wsdlContent, $cacheId, array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG)); } return $wsdlContent; }
/** * Validate nonce and timestamp pair. * Write nonce to storage if it's valid. * * @param string $nonce * @param int $timestamp * @throws Mage_Webapi_Model_Soap_Security_UsernameToken_TimestampRefusedException * @throws Mage_Webapi_Model_Soap_Security_UsernameToken_NonceUsedException */ public function validateNonce($nonce, $timestamp) { $timestamp = (int) $timestamp; $isNonceUsed = $timestamp <= time() - self::NONCE_TTL; $isNonceFromFuture = $timestamp > time() + self::NONCE_FROM_FUTURE_ACCEPTABLE_RANGE; if ($timestamp <= 0 || $isNonceUsed || $isNonceFromFuture) { throw new Mage_Webapi_Model_Soap_Security_UsernameToken_TimestampRefusedException(); } if ($this->_cacheInstance->load($this->getNonceCacheId($nonce)) == $timestamp) { throw new Mage_Webapi_Model_Soap_Security_UsernameToken_NonceUsedException(); } $nonceCacheTtl = self::NONCE_TTL + self::NONCE_FROM_FUTURE_ACCEPTABLE_RANGE; $this->_cacheInstance->save($timestamp, $this->getNonceCacheId($nonce), array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG), $nonceCacheTtl); }
/** * Load system configuration * * @return Mage_Backend_Model_Config_Structure */ public function getConfiguration() { if ($this->_cache->canUse('config')) { $cache = $this->_cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE); if ($cache) { return unserialize($cache); } } $fileNames = $this->_appConfig->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml'); $config = $this->_appConfig->getModelInstance('Mage_Backend_Model_Config_Structure', array('sourceFiles' => $fileNames)); if ($this->_cache->canUse('config')) { $this->_cache->save(serialize($config), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG)); } return $config; }
/** * Load ACL resources from cache * * @return null|string */ private function _loadAclResourcesFromCache() { if ($this->_cache->canUse('config')) { return $this->_cache->load(self::CACHE_ID); } return null; }
public function load($id) { $start = microtime(true) * 1000; $res = parent::load($id); $this->appendLog($res === false ? self::TYPE_LOAD_MISS : self::TYPE_LOAD_HIT, $id, round(microtime(true) * 1000 - $start)); return $res; }
protected function _loadCache() { if ($this->_cache->canUse('config')) { return $this->_cache->load(self::CACHE_ID); } return false; }
public function testCleanType() { /* Setup preconditions */ $this->_model->save('some data with layout cache tag', 'some_cache_id', array('LAYOUT_GENERAL_CACHE_TAG')); $this->_model->invalidateType('layout'); $this->_model->cleanType('layout'); $this->assertFalse($this->_model->load('some_cache_id')); $this->assertEquals(array(), $this->_model->getInvalidatedTypes()); }
/** * Load config data from cache. * * @return bool Return true on successful load; false otherwise */ protected function _loadDataFromCache() { $isLoaded = false; if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) { $cachedData = $this->_cache->load($this->getCacheId()); if ($cachedData !== false) { $this->_data = unserialize($cachedData); $isLoaded = true; } } return $isLoaded; }
/** * Saves 'web/secure/offloader_header' config to cache, only when value was updated * * @return Enterprise_PageCache_Model_Observer */ protected function _checkAndSaveSslOffloaderHeaderToCache() { if (!$this->isCacheEnabled()) { return $this; } $sslOffloaderHeader = trim((string) Mage::getConfig()->getNode(Mage_Core_Model_Store::XML_PATH_OFFLOADER_HEADER, 'default')); $cachedSslOffloaderHeader = $this->_cacheInstance->load(Enterprise_PageCache_Model_Processor::SSL_OFFLOADER_HEADER_KEY); $cachedSslOffloaderHeader = trim(@unserialize($cachedSslOffloaderHeader)); if ($cachedSslOffloaderHeader != $sslOffloaderHeader) { $this->_saveSslOffloaderHeaderToCache($sslOffloaderHeader); } return $this; }
/** * @param Mage_Core_Model_Config $config * @param Mage_Core_Model_Cache $cache * @param Mage_Backend_Model_Config_Structure_Converter $structureConverter * @param bool $runtimeValidation */ public function __construct(Mage_Core_Model_Config $config, Mage_Core_Model_Cache $cache, Mage_Backend_Model_Config_Structure_Converter $structureConverter, $runtimeValidation = true) { $this->_runtimeValidation = $runtimeValidation; $this->_converter = $structureConverter; $this->_config = $config; if ($cache->canUse('config') && ($cachedData = $cache->load(self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE))) { $this->_data = unserialize($cachedData); } else { $fileNames = $this->_config->getModuleConfigurationFiles('adminhtml' . DIRECTORY_SEPARATOR . 'system.xml'); parent::__construct($fileNames); if ($cache->canUse('config')) { $cache->save(serialize($this->_data), self::CACHE_SYSTEM_CONFIGURATION_STRUCTURE, array(Mage_Core_Model_Config::CACHE_TAG)); } } }
/** * @param string $id * @return string */ public function load($id) { $data = parent::load($id); $compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH); if ($data !== false && $compressLevel != -2) { $data = gzuncompress($data); } return $data; }
/** * Loading cache data * * @param string $id * @return mixed */ public function loadCache($id) { return $this->_cache->load($id); }
public function testLoad() { $this->_cacheFrontend->expects($this->once())->method('load')->with('TEST_ID')->will($this->returnValue('test_data')); $this->assertEquals('test_data', $this->_model->load('test_id')); }
public function load($id) { $content = parent::load($id); if ($content) { $prefixLen = strlen(self::COMPRESSION_PREFIX); if (substr($content, 0, $prefixLen) == self::COMPRESSION_PREFIX) { $content = gzuncompress(base64_decode(substr($content, $prefixLen))); } } return $content; }
/** * @param string $id * @return boolean|\Lesti_Fpc_Model_Fpc_CacheItem */ public function load($id) { $data = parent::load($id); if ($data === false) { return false; } $compressLevel = Mage::getStoreConfig(self::GZCOMPRESS_LEVEL_XML_PATH); if ($data !== false && $compressLevel != -2) { $data = gzuncompress($data); } $data = unserialize($data); return new Lesti_Fpc_Model_Fpc_CacheItem($data[0], $data[1], $data[2]); }