/** * @param bool $fixtureResultOne * @param bool $fixtureResultTwo * @param bool $expectedResult * @dataProvider cleanModeMatchingAnyTagDataProvider */ public function testCleanModeMatchingAnyTag($fixtureResultOne, $fixtureResultTwo, $expectedResult) { $this->frontendMock->expects($this->at(0))->method('clean')->with(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['test_tag_one', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG])->will($this->returnValue($fixtureResultOne)); $this->frontendMock->expects($this->at(1))->method('clean')->with(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, ['test_tag_two', \Magento\Framework\App\Cache\Type\Config::CACHE_TAG])->will($this->returnValue($fixtureResultTwo)); $actualResult = $this->model->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['test_tag_one', 'test_tag_two']); $this->assertEquals($expectedResult, $actualResult); }
/** * @param \Magento\Framework\App\FrontController $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if ($this->_appState->isInstalled() && !$this->_cache->load('data_upgrade')) { $this->_dbUpdater->updateScheme(); $this->_dbUpdater->updateData(); $this->_cache->save('true', 'data_upgrade'); } return $proceed($request); }
/** * Update a "layout update link" if relevant data is provided * * @param \Magento\Widget\Model\Layout\Update|\Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $data = $object->getData(); if (isset($data['store_id']) && isset($data['theme_id'])) { $this->getConnection()->insertOnDuplicate($this->getTable('layout_link'), ['store_id' => $data['store_id'], 'theme_id' => $data['theme_id'], 'layout_update_id' => $object->getId(), 'is_temporary' => (int) $object->getIsTemporary()]); } $this->_cache->clean(); return parent::_afterSave($object); }
/** * @param \Magento\Framework\App\FrontController $subject * @param \Closure $proceed * @param \Magento\Framework\App\RequestInterface $request * * @throws \Magento\Framework\Module\Exception * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->cache->load('db_is_up_to_date')) { if (!$this->isDbUpToDate()) { throw new \Magento\Framework\Module\Exception('Looks like database is outdated. Please, use setup tool to perform update'); } else { $this->cache->save('true', 'db_is_up_to_date'); } } return $proceed($request); }
/** * Init cached list of validation files */ protected function _initializeConfigList() { if (!$this->_configFiles) { $this->_configFiles = $this->cache->load(self::CACHE_KEY); if (!$this->_configFiles) { $this->_configFiles = $this->moduleReader->getConfigurationFiles('validation.xml'); $this->cache->save(serialize($this->_configFiles), self::CACHE_KEY); } else { $this->_configFiles = unserialize($this->_configFiles); } } }
/** * Load modules DI configuration * * @param string $area * @return array */ public function load($area) { $cacheId = $area . '::DiConfig'; $data = $this->_cache->load($cacheId); if (!$data) { $data = $this->_reader->read($area); $this->_cache->save(serialize($data), $cacheId); } else { $data = unserialize($data); } return $data; }
/** * {@inheritdoc} */ public function fetchAll(\Zend_Db_Select $select, array $bindParams = array()) { $cacheId = $this->_getSelectCacheId($select); $result = $this->_cache->load($cacheId); if ($result) { $result = unserialize($result); } else { $result = $this->_fetchStrategy->fetchAll($select, $bindParams); $this->_cache->save(serialize($result), $cacheId, $this->_cacheTags, $this->_cacheLifetime); } return $result; }
/** * @param \Magento\Framework\App\FrontController $subject * @param \Closure $proceed * @param \Magento\Framework\App\RequestInterface $request * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->cache->load('db_is_up_to_date')) { $errors = $this->dbVersionInfo->getDbVersionErrors(); if ($errors) { $formattedErrors = $this->formatErrors($errors); throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.' . ' %1The following modules are outdated:%2%3', [PHP_EOL, PHP_EOL, implode(PHP_EOL, $formattedErrors)])); } else { $this->cache->save('true', 'db_is_up_to_date'); } } return $proceed($request); }
/** * @param \Magento\Framework\App\FrontController $subject * @param \Closure $proceed * @param \Magento\Framework\App\RequestInterface $request * * @throws \Magento\Framework\Module\Exception * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->cache->load('db_is_up_to_date')) { $errors = $this->dbVersionInfo->getDbVersionErrors(); if ($errors) { $formattedErrors = $this->formatErrors($errors); throw new \Magento\Framework\Module\Exception('Please update your database: Run "php -f index.php update" from the Magento root/setup directory.' . PHP_EOL . 'The following modules are outdated:' . PHP_EOL . implode(PHP_EOL, $formattedErrors)); } else { $this->cache->save('true', 'db_is_up_to_date'); } } return $proceed($request); }
/** * Return service interface or Data interface methods loaded from cache * * @param string $interfaceName * @return array * <pre> * Service methods' reflection data stored in cache as 'methodName' => 'returnType' * ex. * [ * 'create' => '\Magento\Customer\Api\Data\Customer', * 'validatePassword' => 'boolean' * ] * </pre> */ public function getMethodsMap($interfaceName) { $key = self::SERVICE_INTERFACE_METHODS_CACHE_PREFIX . "-" . md5($interfaceName); if (!isset($this->serviceInterfaceMethodsMap[$key])) { $methodMap = $this->cache->load($key); if ($methodMap) { $this->serviceInterfaceMethodsMap[$key] = unserialize($methodMap); } else { $methodMap = $this->getMethodMapViaReflection($interfaceName); $this->serviceInterfaceMethodsMap[$key] = $methodMap; $this->cache->save(serialize($this->serviceInterfaceMethodsMap[$key]), $key); } } return $this->serviceInterfaceMethodsMap[$key]; }
/** * @param $data * @param $result * @dataProvider dataProviderForTestGetData */ public function testGetData($data, $result) { $this->cache->expects($this->once())->method('load')->will($this->returnValue(serialize($data))); $this->expectsSetConfig('themeId'); $this->translate->loadData('frontend'); $this->assertEquals($result, $this->translate->getData()); }
/** * @param \Magento\Framework\Config\ReaderInterface $reader * @param \Magento\Framework\Config\ScopeListInterface $scopeList * @param \Magento\Framework\Cache\FrontendInterface $cache * @param \Magento\Framework\ObjectManager\Relations $relations * @param \Magento\Framework\Interception\ObjectManager\Config $omConfig * @param \Magento\Framework\ObjectManager\Definition $classDefinitions * @param string $cacheId */ public function __construct(\Magento\Framework\Config\ReaderInterface $reader, \Magento\Framework\Config\ScopeListInterface $scopeList, \Magento\Framework\Cache\FrontendInterface $cache, \Magento\Framework\ObjectManager\Relations $relations, \Magento\Framework\Interception\ObjectManager\Config $omConfig, \Magento\Framework\ObjectManager\Definition $classDefinitions, $cacheId = 'interception') { $this->_omConfig = $omConfig; $this->_relations = $relations; $this->_classDefinitions = $classDefinitions; $this->_cache = $cache; $this->_cacheId = $cacheId; $this->_reader = $reader; $intercepted = $this->_cache->load($this->_cacheId); if ($intercepted !== false) { $this->_intercepted = unserialize($intercepted); } else { $config = array(); foreach ($scopeList->getAllScopes() as $scope) { $config = array_replace_recursive($config, $this->_reader->read($scope)); } unset($config['preferences']); foreach ($config as $typeName => $typeConfig) { if (!empty($typeConfig['plugins'])) { $this->_intercepted[ltrim($typeName, '\\')] = true; } } foreach ($config as $typeName => $typeConfig) { $this->hasPlugins(ltrim($typeName, '\\')); } foreach ($classDefinitions->getClasses() as $class) { $this->hasPlugins($class); } $this->_cache->save(serialize($this->_intercepted), $this->_cacheId); } }
/** * Assign theme to the stores * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param array $stores * @param string $scope * @return $this */ public function assignToStore($theme, array $stores = [], $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES) { $isReassigned = false; $this->_unassignThemeFromStores($theme->getId(), $stores, $scope, $isReassigned); if ($this->_storeManager->isSingleStoreMode()) { $this->_assignThemeToDefaultScope($theme->getId(), $isReassigned); } else { $this->_assignThemeToStores($theme->getId(), $stores, $scope, $isReassigned); } if ($isReassigned) { $this->_configCache->clean(); $this->_layoutCache->clean(); } $this->_eventManager->dispatch('assign_theme_to_stores_after', ['stores' => $stores, 'scope' => $scope, 'theme' => $theme]); return $this; }
public function testGenerateElementsWithCache() { $layoutCacheId = 'layout_cache_id'; /** @var \Magento\Framework\View\Layout\Element $xml */ $xml = simplexml_load_string('<layout/>', 'Magento\Framework\View\Layout\Element'); $this->model->setXml($xml); $themeMock = $this->getMockForAbstractClass('Magento\Framework\View\Design\ThemeInterface'); $this->themeResolverMock->expects($this->once()) ->method('get') ->willReturn($themeMock); $this->processorFactoryMock->expects($this->once()) ->method('create') ->with(['theme' => $themeMock]) ->willReturn($this->processorMock); $this->processorMock->expects($this->once()) ->method('getCacheId') ->willReturn($layoutCacheId); $readerContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Reader\Context') ->disableOriginalConstructor() ->getMock(); $this->cacheMock->expects($this->once()) ->method('load') ->with('structure_' . $layoutCacheId) ->willReturn(serialize($readerContextMock)); $this->readerPoolMock->expects($this->never()) ->method('interpret'); $this->cacheMock->expects($this->never()) ->method('save'); $generatorContextMock = $this->getMockBuilder('Magento\Framework\View\Layout\Generator\Context') ->disableOriginalConstructor() ->getMock(); $this->generatorContextFactoryMock->expects($this->once()) ->method('create') ->with(['structure' => $this->structureMock, 'layout' => $this->model]) ->willReturn($generatorContextMock); $this->generatorPoolMock->expects($this->once()) ->method('process') ->with($readerContextMock, $generatorContextMock) ->willReturn(true); $elements = [ 'name_1' => ['type' => '', 'parent' => null], 'name_2' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => null], 'name_3' => ['type' => '', 'parent' => 'parent'], 'name_4' => ['type' => \Magento\Framework\View\Layout\Element::TYPE_CONTAINER, 'parent' => 'parent'], ]; $this->structureMock->expects($this->once()) ->method('exportElements') ->willReturn($elements); $this->model->generateElements(); }
public function testPersist() { $cacheTypes = array('cache_type' => false); $model = $this->_buildModel($cacheTypes); $this->_resource->expects($this->once())->method('saveAllOptions')->with($cacheTypes); $this->_cacheFrontend->expects($this->once())->method('remove')->with(\Magento\Framework\App\Cache\State::CACHE_ID); $model->persist(); }
/** * Persists a cache item immediately. * * @param CacheItemInterface $item * The cache item to save. * * @return bool * True if the item was successfully persisted. False if there was an error. * * @throws InvalidArgumentException */ public function save(CacheItemInterface $item) { $expirationTime = null; if ($item instanceof ExtractableCacheLifetimeInterface) { $expirationTime = $item->getCacheLifetime(); } return $this->cacheFrontend->save(serialize($item instanceof ExtractableCacheValueInterface ? $item->getCacheValue() : $item->get()), $this->prepareKey($item->getKey()), $this->tags, $expirationTime); }
/** * {@inheritdoc} */ public function reinitStores() { $this->currentStoreId = null; $this->storeRepository->clean(); $this->websiteRepository->clean(); $this->groupRepository->clean(); $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [StoreResolver::CACHE_TAG]); }
/** * Fetch routes from configs by area code and router id * * @param string $scope * @return array */ protected function _getRoutes($scope = null) { $scope = $scope ?: $this->_configScope->getCurrentScope(); if (isset($this->_routes[$scope])) { return $this->_routes[$scope]; } $cacheId = $scope . '::' . $this->_cacheId; $cachedRoutes = unserialize($this->_cache->load($cacheId)); if (is_array($cachedRoutes)) { $this->_routes[$scope] = $cachedRoutes; return $cachedRoutes; } $routers = $this->_reader->read($scope); $routes = $routers[$this->_areaList->getDefaultRouter($scope)]['routes']; $this->_cache->save(serialize($routes), $cacheId); $this->_routes[$scope] = $routes; return $routes; }
function it_commits_deferred_cache_items_only_onces(CacheItemInterface $cacheItem) { $cacheItem->get()->willReturn([1, 2, 3])->shouldBeCalledTimes(1); $cacheItem->getKey()->willReturn('key1')->shouldBeCalledTimes(1); $this->cacheFrontend->save(serialize([1, 2, 3]), 'prefix_key1', ['tag1', 'tag2'], null)->willReturn(true)->shouldBeCalledTimes(1); $this->saveDeferred($cacheItem)->shouldReturn(true); $this->commit()->shouldReturn(true); // This time nothing should happen $this->commit()->shouldReturn(true); }
public function testClean() { $this->_cache->expects( $this->once() )->method( 'clean' )->with( \Zend_Cache::CLEANING_MODE_MATCHING_TAG, [\Magento\Framework\App\Config\ScopePool::CACHE_TAG] ); $this->_object->clean('testScope'); }
/** * Get stores data * * @return array */ protected function getStoresData() { $cacheKey = 'resolved_stores_' . md5($this->runMode . $this->scopeCode); $cacheData = $this->cache->load($cacheKey); if ($cacheData) { $storesData = unserialize($cacheData); } else { $storesData = $this->readStoresData(); $this->cache->save(serialize($storesData), $cacheKey, [self::CACHE_TAG]); } return $storesData; }
/** * Get methods map for the type: [methodName=>[type,isRequired, description,parameterCount], ...] * * @param string $typeName class/interface name (\Vendor\Package\Space\Type) * @return array */ public function getMap($typeName) { if (!isset($this->_map[$typeName])) { /* try to load from cache */ $key = self::CACHE_PREFIX . "-" . md5($typeName); $cached = $this->_cache->load($key); if ($cached) { /* get, un-serialize and register cached data */ $meta = unserialize($cached); $parsed = $this->_parseMetaData($meta); $this->_map[$typeName] = $parsed; } else { /* launch type methods analyzer and save results to the cache */ $meta = $this->_analyzer->getMethods($typeName); $parsed = $this->_parseMetaData($meta); $this->_map[$typeName] = $parsed; $cached = serialize($meta); $this->_cache->save($cached, $key); } } $result = $this->_map[$typeName]; return $result; }
/** * Clean cached data by specific tag * * @param array $tags * @return bool */ public function clean($tags = array()) { if ($tags) { $result = $this->_frontend->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array) $tags); } else { /** @deprecated special case of cleaning by empty tags is deprecated after 2.0.0.0-dev42 */ $result = false; /** @var $cacheFrontend \Magento\Framework\Cache\FrontendInterface */ foreach ($this->_frontendPool as $cacheFrontend) { if ($cacheFrontend->clean()) { $result = true; } } } return $result; }
/** * Retrieve requested service method params metadata. * * @param string $serviceClassName * @param string $serviceMethodName * @return array */ public function getMethodParams($serviceClassName, $serviceMethodName) { $cacheId = self::SERVICE_METHOD_PARAMS_CACHE_PREFIX . hash('md5', $serviceClassName . $serviceMethodName); $params = $this->cache->load($cacheId); if ($params !== false) { return unserialize($params); } $serviceClass = new ClassReflection($serviceClassName); /** @var MethodReflection $serviceMethod */ $serviceMethod = $serviceClass->getMethod($serviceMethodName); $params = []; /** @var ParameterReflection $paramReflection */ foreach ($serviceMethod->getParameters() as $paramReflection) { $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable(); $params[] = [self::METHOD_META_NAME => $paramReflection->getName(), self::METHOD_META_TYPE => $this->typeProcessor->getParamType($paramReflection), self::METHOD_META_HAS_DEFAULT_VALUE => $isDefaultValueAvailable, self::METHOD_META_DEFAULT_VALUE => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null]; } $this->cache->save(serialize($params), $cacheId, [ReflectionCache::CACHE_TAG]); return $params; }
/** * Initialize interception config * * @param array $classDefinitions * @return void */ public function initialize($classDefinitions = []) { $this->_cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, [$this->_cacheId]); $config = []; foreach ($this->_scopeList->getAllScopes() as $scope) { $config = array_replace_recursive($config, $this->_reader->read($scope)); } unset($config['preferences']); foreach ($config as $typeName => $typeConfig) { if (!empty($typeConfig['plugins'])) { $this->_intercepted[ltrim($typeName, '\\')] = true; } } foreach ($config as $typeName => $typeConfig) { $this->hasPlugins($typeName); } foreach ($classDefinitions as $class) { $this->hasPlugins($class); } $this->_cache->save(serialize($this->_intercepted), $this->_cacheId); }
/** * Create structure of elements from the loaded XML configuration * * @return void */ public function generateElements() { \Magento\Framework\Profiler::start(__CLASS__ . '::' . __METHOD__); $cacheId = 'structure_' . $this->getUpdate()->getCacheId(); $result = $this->cache->load($cacheId); if ($result) { $this->readerContext = unserialize($result); } else { \Magento\Framework\Profiler::start('build_structure'); $this->readerPool->interpret($this->getReaderContext(), $this->getNode()); \Magento\Framework\Profiler::stop('build_structure'); $this->cache->save(serialize($this->getReaderContext()), $cacheId, $this->getUpdate()->getHandles()); } $generatorContext = $this->generatorContextFactory->create(['structure' => $this->structure, 'layout' => $this]); \Magento\Framework\Profiler::start('generate_elements'); $this->generatorPool->process($this->getReaderContext(), $generatorContext); \Magento\Framework\Profiler::stop('generate_elements'); $this->addToOutputRootContainers(); \Magento\Framework\Profiler::stop(__CLASS__ . '::' . __METHOD__); }
/** * Saving data cache * * @return $this */ protected function _saveCache() { $this->_cache->save(serialize($this->getData()), $this->getCacheId(true), [], false); return $this; }
/** * Save data to the cache, if the layout caching is allowed * * @param string $data * @param string $cacheId * @param array $cacheTags * @return void */ protected function _saveCache($data, $cacheId, array $cacheTags = []) { $this->cache->save($data, $cacheId, $cacheTags, null); }
/** * Advanced save procedure * * @return void */ protected function _saveAdvanced() { $this->_cache->clean(); }
/** * Reset cached DDL data from cache * if table name is null - reset all cached DDL data * * @param string $tableName * @param string $schemaName OPTIONAL * @return $this */ public function resetDdlCache($tableName = null, $schemaName = null) { if (!$this->_isDdlCacheAllowed) { return $this; } if ($tableName === null) { $this->_ddlCache = array(); if ($this->_cacheAdapter) { $this->_cacheAdapter->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(self::DDL_CACHE_TAG)); } } else { $cacheKey = $this->_getTableName($tableName, $schemaName); $ddlTypes = array(self::DDL_DESCRIBE, self::DDL_CREATE, self::DDL_INDEX, self::DDL_FOREIGN_KEY); foreach ($ddlTypes as $ddlType) { unset($this->_ddlCache[$ddlType][$cacheKey]); } if ($this->_cacheAdapter) { foreach ($ddlTypes as $ddlType) { $cacheId = $this->_getCacheId($cacheKey, $ddlType); $this->_cacheAdapter->remove($cacheId); } } } return $this; }