/** * 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; }
/** * 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; }
/** * @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 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; }
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; }
/** * Disable some cache types in VDE mode */ protected function _disableCache() { foreach ($this->_dataHelper->getDisabledCacheTypes() as $cacheCode) { if ($this->_cacheManager->canUse($cacheCode)) { $this->_cacheManager->banUse($cacheCode); } } }
public function testCanUseAndBanUse() { $actualCacheOptions = $this->_model->canUse(''); $this->assertEquals(array('config' => true), $actualCacheOptions); $this->assertTrue($this->_model->canUse('config')); $this->_model->banUse('config'); $this->assertFalse($this->_model->canUse('config')); }
/** * @depends testBanUse * @param Mage_Core_Model_Cache $model */ public function testAllowUse(Mage_Core_Model_Cache $model) { $this->assertFalse($model->canUse('config')); //$model->allowUse('config'); $this->assertTrue($model->canUse('config')); }
/** * Check whether to use cache for specific component * * @return boolean */ public function useCache($type = null) { return $this->_cache->canUse($type); }
/** * @depends testBanUse * @param Mage_Core_Model_Cache $model */ public function testAllowUse(Mage_Core_Model_Cache $model) { $this->_emulateCacheTypeOptions(); $this->assertFalse($model->canUse('config')); $model->allowUse('config'); $this->assertTrue($model->canUse('config')); }
/** * 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)); } }