function it_checks_if_item_exists_in_cache_without_creating_cache_item()
 {
     $this->cacheFrontend->load('prefix_key1')->willReturn(serialize('test'));
     $this->cacheFrontend->load('prefix_key2')->willReturn(false);
     $this->cacheItemFactory->create(Argument::any())->shouldNotBeCalled();
     $this->hasItem('key1')->shouldReturn(true);
     $this->hasItem('key2')->shouldReturn(false);
 }
示例#2
0
 /**
  * @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);
 }
 /**
  * @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);
 }
示例#4
0
 /**
  * {@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;
 }
示例#5
0
 /**
  * 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);
         }
     }
 }
示例#6
0
 /**
  * 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;
 }
 /**
  * @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);
 }
示例#9
0
 /**
  * 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];
 }
示例#10
0
 /**
  * @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);
     }
 }
示例#11
0
 /**
  * Retrieve config section
  *
  * @param string $scopeType
  * @param string|\Magento\Framework\DataObject|null $scopeCode
  * @return \Magento\Framework\App\Config\DataInterface
  */
 public function getScope($scopeType, $scopeCode = null)
 {
     $scopeCode = $this->_getScopeCode($scopeType, $scopeCode);
     $code = $scopeType . '|' . $scopeCode;
     if (!isset($this->_scopes[$code])) {
         // Key by url to support dynamic {{base_url}} and port assignments
         $host = $this->getRequest()->getHttpHost();
         $port = $this->getRequest()->getServer('SERVER_PORT');
         $path = $this->getRequest()->getBasePath();
         $urlInfo = $host . $port . trim($path, '/');
         $cacheKey = $this->_cacheId . '|' . $code . '|' . $urlInfo;
         $data = $this->_cache->load($cacheKey);
         if ($data) {
             $data = unserialize($data);
         } else {
             $reader = $this->_readerPool->getReader($scopeType);
             if ($scopeType === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
                 $data = $reader->read();
             } else {
                 $data = $reader->read($scopeCode);
             }
             $this->_cache->save(serialize($data), $cacheKey, [self::CACHE_TAG]);
         }
         $this->_scopes[$code] = $this->_dataFactory->create(['data' => $data]);
     }
     return $this->_scopes[$code];
 }
示例#12
0
 /**
  * @param \Magento\Framework\Config\ReaderInterface $reader
  * @param \Magento\Framework\Config\ScopeListInterface $scopeList
  * @param \Magento\Framework\Cache\FrontendInterface $cache
  * @param \Magento\Framework\ObjectManager\RelationsInterface $relations
  * @param \Magento\Framework\Interception\ObjectManager\ConfigInterface $omConfig
  * @param \Magento\Framework\ObjectManager\DefinitionInterface $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\RelationsInterface $relations, \Magento\Framework\Interception\ObjectManager\ConfigInterface $omConfig, \Magento\Framework\ObjectManager\DefinitionInterface $classDefinitions, $cacheId = 'interception')
 {
     $this->_omConfig = $omConfig;
     $this->_relations = $relations;
     $this->_classDefinitions = $classDefinitions;
     $this->_cache = $cache;
     $this->_cacheId = $cacheId;
     $this->_reader = $reader;
     $this->_scopeList = $scopeList;
     $intercepted = $this->_cache->load($this->_cacheId);
     if ($intercepted !== false) {
         $this->_intercepted = unserialize($intercepted);
     } else {
         $this->initialize($this->_classDefinitions->getClasses());
     }
 }
 /**
  * Confirms if the cache contains specified cache item.
  *
  * Note: This method MAY avoid retrieving the cached value for performance reasons.
  * This could result in a race condition with CacheItemInterface::get(). To avoid
  * such situation use CacheItemInterface::isHit() instead.
  *
  * @param string $key
  *    The key for which to check existence.
  *
  * @throws InvalidArgumentException
  *   If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
  *   MUST be thrown.
  *
  * @return bool
  *  True if item exists in the cache, false otherwise.
  */
 public function hasItem($key)
 {
     if ($this->cacheFrontend->load($this->prepareKey($key)) !== false) {
         return true;
     }
     return false;
 }
示例#14
0
 /**
  * Load statuses (enabled/disabled) of cache types
  *
  * @param bool $forceDisableAll
  * @return void
  */
 private function _loadTypeStatuses($forceDisableAll = false)
 {
     $typeOptions = $this->_cacheFrontend->load(self::CACHE_ID);
     if ($typeOptions !== false) {
         $typeOptions = unserialize($typeOptions);
     } else {
         $typeOptions = $this->_options->getAllOptions();
         if ($typeOptions !== false) {
             $this->_cacheFrontend->save(serialize($typeOptions), self::CACHE_ID);
         }
     }
     if ($typeOptions) {
         foreach ($typeOptions as $cacheType => $isTypeEnabled) {
             $this->setEnabled($cacheType, $isTypeEnabled && !$forceDisableAll);
         }
     }
 }
示例#15
0
 /**
  * Loading data cache
  *
  * @return array|bool
  */
 protected function _loadCache()
 {
     $data = $this->_cache->load($this->getCacheId());
     if ($data) {
         $data = unserialize($data);
     }
     return $data;
 }
示例#16
0
 /**
  * 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;
 }
 /**
  * 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;
 }
示例#18
0
 /**
  * Retrieve config section
  *
  * @param string $scopeType
  * @param string|\Magento\Framework\DataObject|null $scopeCode
  * @return \Magento\Framework\App\Config\DataInterface
  */
 public function getScope($scopeType, $scopeCode = null)
 {
     $scopeCode = $this->_getScopeCode($scopeType, $scopeCode);
     $code = $scopeType . '|' . $scopeCode;
     if (!isset($this->_scopes[$code])) {
         $cacheKey = $this->_cacheId . '|' . $code;
         $data = $this->_cache->load($cacheKey);
         if ($data) {
             $data = unserialize($data);
         } else {
             $reader = $this->_readerPool->getReader($scopeType);
             if ($scopeType === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
                 $data = $reader->read();
             } else {
                 $data = $reader->read($scopeCode);
             }
             $this->_cache->save(serialize($data), $cacheKey, [self::CACHE_TAG]);
         }
         $this->_scopes[$code] = $this->_dataFactory->create(['data' => $data]);
     }
     return $this->_scopes[$code];
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 /**
  * 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;
 }
示例#21
0
 /**
  * Retrieve configuration from cache
  *
  * @param string $key
  * @return array
  */
 public function get($key)
 {
     return unserialize($this->_cacheFrontend->load($this->_prefix . $key));
 }
示例#22
0
 /**
  * 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__);
 }
示例#23
0
 /**
  * Retrieve data from the cache, if the layout caching is allowed, or FALSE otherwise
  *
  * @param string $cacheId
  * @return string|bool
  */
 protected function _loadCache($cacheId)
 {
     return $this->cache->load($cacheId);
 }
 /**
  * Retrieve configurable attributes data
  *
  * @param  \Magento\Catalog\Model\Product $product
  * @return \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute[]
  */
 public function getConfigurableAttributes($product)
 {
     \Magento\Framework\Profiler::start('CONFIGURABLE:' . __METHOD__, ['group' => 'CONFIGURABLE', 'method' => __METHOD__]);
     if (!$product->hasData($this->_configurableAttributes)) {
         $cacheId = __CLASS__ . $product->getId();
         $configurableAttributes = $this->cache->load($cacheId);
         if ($configurableAttributes) {
             $configurableAttributes = unserialize($configurableAttributes);
             $configurableAttributes->setProductFilter($product);
         } else {
             $configurableAttributes = $this->getConfigurableAttributeCollection($product);
             $this->extensionAttributesJoinProcessor->process($configurableAttributes);
             $configurableAttributes->orderByPosition()->load();
             $this->cache->save(serialize($configurableAttributes), $cacheId, $product->getIdentities());
         }
         $product->setData($this->_configurableAttributes, $configurableAttributes);
     }
     \Magento\Framework\Profiler::stop('CONFIGURABLE:' . __METHOD__);
     return $product->getData($this->_configurableAttributes);
 }
示例#25
0
 /**
  * Load DDL data from cache
  * Return false if cache does not exists
  *
  * @param string $tableCacheKey the table cache key
  * @param int $ddlType          the DDL constant
  * @return string|array|int|false
  */
 public function loadDdlCache($tableCacheKey, $ddlType)
 {
     if (!$this->_isDdlCacheAllowed) {
         return false;
     }
     if (isset($this->_ddlCache[$ddlType][$tableCacheKey])) {
         return $this->_ddlCache[$ddlType][$tableCacheKey];
     }
     if ($this->_cacheAdapter) {
         $cacheId = $this->_getCacheId($tableCacheKey, $ddlType);
         $data = $this->_cacheAdapter->load($cacheId);
         if ($data !== false) {
             $data = unserialize($data);
             $this->_ddlCache[$ddlType][$tableCacheKey] = $data;
         }
         return $data;
     }
     return false;
 }
示例#26
0
 /**
  * Load data from cache by id
  *
  * @param  string $identifier
  * @return string
  */
 public function load($identifier)
 {
     return $this->_frontend->load($identifier);
 }