/** * 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; }
/** * 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; }
/** * Save ACL resources into the cache * * @param $data * @return Mage_Backend_Model_Acl_Config */ private function _saveAclResourcesToCache($data) { if ($this->_cache->canUse('config')) { $this->_cache->save($data, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG)); } return $this; }
public function save($data, $id, $tags = array(), $lifeTime = null) { $start = microtime(true) * 1000; $res = parent::save($data, $id, $tags, $lifeTime); $this->appendLog(self::TYPE_SAVE, $id, round(microtime(true) * 1000 - $start)); return $res; }
protected function _saveCache($xml) { if ($this->_cache->canUse('config')) { $this->_cache->save($xml, self::CACHE_ID, array(Mage_Core_Model_Config::CACHE_TAG)); } return $this; }
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()); }
/** * @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)); } } }
/** * Save 'web/secure/offloader_header' config to cache * * @param $value */ protected function _saveSslOffloaderHeaderToCache($value) { $this->_cacheInstance->save(serialize($value), Enterprise_PageCache_Model_Processor::SSL_OFFLOADER_HEADER_KEY, array(Enterprise_PageCache_Model_Processor::CACHE_TAG)); }
/** * Saving cache data * * @param mixed $data * @param string $id * @param array $tags * @return Mage_Core_Model_App */ public function saveCache($data, $id, $tags = array(), $lifeTime = false) { $this->_cache->save($data, $id, $tags, $lifeTime); return $this; }
public function testSaveDisallowed() { $model = new Mage_Core_Model_Cache(array('config' => $this->_config, 'helper' => $this->_helper, 'frontend' => $this->_cacheFrontend, 'backend' => 'BlackHole', 'disallow_save' => true)); $this->_cacheFrontend->expects($this->never())->method('save'); $model->save('test_data', 'test_id'); }
/** * Save data to cache if it is enabled. */ protected function _saveDataToCache() { if ($this->_cache->canUse(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_NAME)) { $this->_cache->save(serialize($this->_data), $this->getCacheId(), array(Mage_Webapi_Model_ConfigAbstract::WEBSERVICE_CACHE_TAG)); } }
/** * Resave exception rules to cache storage * * @param Varien_Event_Observer $observer * @return Enterprise_PageCache_Model_Observer */ public function registerDesignExceptionsChange(Varien_Event_Observer $observer) { $object = $observer->getDataObject(); $this->_cacheInstance->save($object->getValue(), Enterprise_PageCache_Model_Processor::DESIGN_EXCEPTION_KEY, array(Enterprise_PageCache_Model_Processor::CACHE_TAG)); return $this; }
public function _savePage($data, $id, $tags = array(), $lifeTime = null) { $data = serialize($data); if (Mage::helper('amfpc')->isPageCompressionEnabled()) { $data = gzcompress($data, +Mage::getStoreConfig('amfpc/compression/level')); $data = base64_encode($data); $data = self::COMPRESSION_PREFIX . $data; } if (self::STATS_MODE) { Mage::getModel('amfpc/stats')->load($id, 'cache_id')->addData(array('cache_id' => $id, 'url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'size' => strlen($data), 'type' => 'page', 'customer_group' => Mage::getSingleton('amfpc/fpc_front')->getCustomerGroupId(), 'session' => $_COOKIE['frontend']))->save(); } return parent::save($data, $id, $tags, $lifeTime); }