Пример #1
0
 public function testReset()
 {
     $cacheid = 'test';
     $this->cache->expects($this->once())->method('load')->will($this->returnValue(serialize([])));
     $this->cache->expects($this->once())->method('remove')->with($cacheid);
     $config = new \Magento\Framework\Config\Data($this->reader, $this->cache, $cacheid);
     $config->reset();
 }
Пример #2
0
 /**
  * @param \Magento\Indexer\Model\Config\Reader $reader
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param \Magento\Indexer\Model\Resource\Indexer\State\Collection $stateCollection
  * @param string $cacheId
  */
 public function __construct(\Magento\Indexer\Model\Config\Reader $reader, \Magento\Framework\Config\CacheInterface $cache, \Magento\Indexer\Model\Resource\Indexer\State\Collection $stateCollection, $cacheId = 'indexer_config')
 {
     $this->stateCollection = $stateCollection;
     $isCacheExists = $cache->test($cacheId);
     parent::__construct($reader, $cache, $cacheId);
     if (!$isCacheExists) {
         $this->deleteNonexistentStates();
     }
 }
Пример #3
0
 /**
  * @param \Magento\Framework\Mview\Config\Reader $reader
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param \Magento\Framework\Mview\View\State\CollectionInterface $stateCollection
  * @param string $cacheId
  */
 public function __construct(\Magento\Framework\Mview\Config\Reader $reader, \Magento\Framework\Config\CacheInterface $cache, \Magento\Framework\Mview\View\State\CollectionInterface $stateCollection, $cacheId = 'mview_config')
 {
     $this->stateCollection = $stateCollection;
     $isCacheExists = $cache->test($cacheId);
     parent::__construct($reader, $cache, $cacheId);
     if (!$isCacheExists) {
         $this->deleteNonexistentStates();
     }
 }
Пример #4
0
 /**
  * Get template content
  *
  * @param string $template
  * @return string
  * @throws \Exception
  */
 public function getTemplate($template)
 {
     $hash = sprintf('%x', crc32($template));
     if (isset($this->cachedTemplates[$hash])) {
         return $this->cachedTemplates[$hash];
     }
     $this->cachedTemplates[$hash] = $this->readerFactory->create(['fileCollector' => $this->aggregatedFileCollectorFactory->create(['searchPattern' => $template]), 'domMerger' => $this->domMerger])->getContent();
     $this->cache->save(serialize($this->cachedTemplates), static::CACHE_ID);
     return $this->cachedTemplates[$hash];
 }
Пример #5
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\Config\ReaderInterface $reader
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param string $cacheId
  */
 public function __construct(\Magento\Framework\Config\ReaderInterface $reader, \Magento\Framework\Config\CacheInterface $cache, $cacheId)
 {
     $data = $cache->load($cacheId);
     if (false === $data) {
         $data = $reader->read();
         $cache->save(serialize($data), $cacheId);
     } else {
         $data = unserialize($data);
     }
     $this->merge($data);
 }
Пример #6
0
 /**
  * @param Filesystem $reader
  * @param CacheInterface $cache
  * @param string $cacheId
  */
 public function __construct(Filesystem $reader, CacheInterface $cache, $cacheId = 'modules_declaration_cache')
 {
     $data = $cache->load($this->_scope . '::' . $cacheId);
     if (!$data) {
         $data = $reader->read($this->_scope);
         $cache->save(serialize($data), $this->_scope . '::' . $cacheId);
     } else {
         $data = unserialize($data);
     }
     $this->_data = $data;
 }
Пример #7
0
 /**
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param ModuleReader $moduleReader
  * @param string $actionInterface
  * @param string $cacheKey
  * @param array $reservedWords
  */
 public function __construct(\Magento\Framework\Config\CacheInterface $cache, ModuleReader $moduleReader, $actionInterface = '\\Magento\\Framework\\App\\ActionInterface', $cacheKey = 'app_action_list', $reservedWords = [])
 {
     $this->reservedWords = array_merge($reservedWords, $this->reservedWords);
     $this->actionInterface = $actionInterface;
     $data = $cache->load($cacheKey);
     if (!$data) {
         $this->actions = $moduleReader->getActionFiles();
         $cache->save(serialize($this->actions), $cacheKey);
     } else {
         $this->actions = unserialize($data);
     }
 }
Пример #8
0
 /**
  * @param \Magento\Framework\Config\CacheInterface $cache
  * @param ActionList\Reader $actionReader
  * @param string $actionInterface
  * @param string $cacheKey
  * @param array $reservedWords
  */
 public function __construct(\Magento\Framework\Config\CacheInterface $cache, ActionList\Reader $actionReader, $actionInterface = '\\Magento\\Framework\\App\\ActionInterface', $cacheKey = 'app_action_list', $reservedWords = array('new', 'switch', 'return', 'print', 'list'))
 {
     $this->reservedWords = $reservedWords;
     $this->actionInterface = $actionInterface;
     $data = $cache->load($cacheKey);
     if (!$data) {
         $this->actions = $actionReader->read();
         $cache->save(serialize($this->actions), $cacheKey);
     } else {
         $this->actions = unserialize($data);
     }
 }
Пример #9
0
 /**
  * Initialise data for configuration
  * @return void
  */
 protected function initData()
 {
     $data = $this->cache->load($this->cacheId);
     if (false === $data) {
         $singleQuery = $this->config->getConnectionName('checkout_setup') == 'default' ? true : false;
         $data['checkout'] = $singleQuery;
         $this->cache->save(serialize($data), $this->cacheId, $this->cacheTags);
     } else {
         $data = unserialize($data);
     }
     $this->merge($data);
 }
Пример #10
0
 /**
  * Constructor
  *
  * @param UiReaderInterface $uiReader
  * @param ArrayObjectFactory $arrayObjectFactory
  * @param CacheInterface $cache
  */
 public function __construct(UiReaderInterface $uiReader, ArrayObjectFactory $arrayObjectFactory, CacheInterface $cache)
 {
     $this->cache = $cache;
     $this->componentData = $arrayObjectFactory->create();
     $cachedData = $this->cache->load(static::CACHE_ID);
     if ($cachedData === false) {
         $data = $uiReader->read();
         $this->cache->save(serialize($data), static::CACHE_ID);
     } else {
         $data = unserialize($cachedData);
     }
     $this->prepareComponentData($data);
 }
Пример #11
0
 public function testConstructorWithoutCache()
 {
     $this->cache->expects($this->once())->method('test')->with($this->cacheId)->will($this->returnValue(false));
     $this->cache->expects($this->once())->method('load')->with($this->cacheId)->will($this->returnValue(false));
     $this->reader->expects($this->once())->method('read')->will($this->returnValue($this->indexers));
     $stateExistent = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getIndexerId', '__wakeup', 'delete'], [], '', false);
     $stateExistent->expects($this->once())->method('getIndexerId')->will($this->returnValue('indexer1'));
     $stateExistent->expects($this->never())->method('delete');
     $stateNonexistent = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getIndexerId', '__wakeup', 'delete'], [], '', false);
     $stateNonexistent->expects($this->once())->method('getIndexerId')->will($this->returnValue('indexer2'));
     $stateNonexistent->expects($this->once())->method('delete');
     $states = [$stateExistent, $stateNonexistent];
     $this->stateCollection->expects($this->once())->method('getItems')->will($this->returnValue($states));
     $this->model = new \Magento\Indexer\Model\Config\Data($this->reader, $this->cache, $this->stateCollection, $this->cacheId);
 }
Пример #12
0
 public function testConstructorWithoutCache()
 {
     $this->cache->expects($this->once())->method('test')->with($this->cacheId)->will($this->returnValue(false));
     $this->cache->expects($this->once())->method('load')->with($this->cacheId)->will($this->returnValue(false));
     $this->reader->expects($this->once())->method('read')->will($this->returnValue($this->views));
     $stateExistent = $this->getMock('Magento\\Framework\\Mview\\Indexer\\State', array('getViewId', '__wakeup', 'delete'), array(), '', false);
     $stateExistent->expects($this->once())->method('getViewId')->will($this->returnValue('view1'));
     $stateExistent->expects($this->never())->method('delete');
     $stateNonexistent = $this->getMock('Magento\\Framework\\Mview\\Indexer\\State', array('getViewId', '__wakeup', 'delete'), array(), '', false);
     $stateNonexistent->expects($this->once())->method('getViewId')->will($this->returnValue('view2'));
     $stateNonexistent->expects($this->once())->method('delete');
     $states = array($stateExistent, $stateNonexistent);
     $this->stateCollection->expects($this->once())->method('getItems')->will($this->returnValue($states));
     $this->model = new \Magento\Framework\Mview\Config\Data($this->reader, $this->cache, $this->stateCollection, $this->cacheId);
 }
Пример #13
0
 /**
  * Call method around dispatch frontend action
  *
  * @param FrontControllerInterface $subject
  * @param \Closure                 $proceed
  * @param RequestInterface         $request
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD)
  */
 public function aroundDispatch(FrontControllerInterface $subject, \Closure $proceed, RequestInterface $request)
 {
     $startTime = microtime(true);
     if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
         $startTime = $_SERVER['REQUEST_TIME_FLOAT'];
     }
     /** @var \Magento\Framework\App\Request\Http $request */
     if (strpos($request->getOriginalPathInfo(), 'searchautocomplete/ajax/suggest') !== false) {
         $this->result->init();
         $proceed($request);
         #require for init translations
         $request->setControllerModule('Magento_CatalogSearch');
         $request->setDispatched(true);
         $identifier = 'QUERY_' . $this->storeManager->getStore()->getId() . '_' . md5($request->getParam('q'));
         if ($result = $this->cache->load($identifier)) {
             $result = \Zend_Json::decode($result);
             $result['time'] = round(microtime(true) - $startTime, 4);
             $result['cache'] = true;
             $data = \Zend_Json::encode($result);
         } else {
             // mirasvit core event
             $this->eventManager->dispatch('core_register_urlrewrite');
             $result = $this->result->toArray();
             $result['success'] = true;
             $result['time'] = round(microtime(true) - $startTime, 4);
             $result['cache'] = false;
             $data = \Zend_Json::encode($result);
             $this->cache->save($data, $identifier, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]);
         }
         $this->response->setPublicHeaders(3600);
         return $this->response->representJson($data);
     } else {
         return $proceed($request);
     }
 }
Пример #14
0
 /**
  * Load data for current scope
  *
  * @return void
  */
 protected function _loadScopedData()
 {
     $scope = $this->_configScope->getCurrentScope();
     if (false == isset($this->_loadedScopes[$scope])) {
         if (false == in_array($scope, $this->_scopePriorityScheme)) {
             $this->_scopePriorityScheme[] = $scope;
         }
         foreach ($this->_scopePriorityScheme as $scopeCode) {
             if (false == isset($this->_loadedScopes[$scopeCode])) {
                 if ($scopeCode !== 'primary' && ($data = $this->_cache->load($scopeCode . '::' . $this->_cacheId))) {
                     $data = unserialize($data);
                 } else {
                     $data = $this->_reader->read($scopeCode);
                     if ($scopeCode !== 'primary') {
                         $this->_cache->save(serialize($data), $scopeCode . '::' . $this->_cacheId);
                     }
                 }
                 $this->merge($data);
                 $this->_loadedScopes[$scopeCode] = true;
             }
             if ($scopeCode == $scope) {
                 break;
             }
         }
     }
 }
Пример #15
0
 protected function processQuery($query)
 {
     $store = $this->storeManager->getDefaultStoreView();
     $part = '';
     for ($i = 0; $i < strlen($query); $i++) {
         $part .= $query[$i];
         $identifier = 'QUERY_' . $store->getId() . '_' . md5($part);
         if (!$this->cache->load($identifier)) {
             $ts = microtime(true);
             $url = $store->getUrl('searchautocomplete/ajax/suggest', ['_query' => ['q' => $part]]);
             try {
                 file_get_contents($url);
             } catch (\Exception $e) {
             }
             $time = round(microtime(true) - $ts, 2);
             echo "'{$part}' has cached ({$time})" . PHP_EOL;
         } else {
             echo "'{$part}' in cache" . PHP_EOL;
         }
     }
 }
Пример #16
0
 /**
  * @dataProvider getComponentData()
  */
 public function testPrepareGetData($componentName, $componentData, $isCached, $readerData, $expectedResult)
 {
     $this->readerFactory->expects($this->any())->method('create')->with(['fileCollector' => $this->aggregatedFileCollector, 'domMerger' => $this->domMerger])->willReturn($this->uiReader);
     $this->aggregatedFileCollectorFactory->expects($this->any())->method('create')->willReturn($this->aggregatedFileCollector);
     $this->argumentInterpreter->expects($this->any())->method('evaluate')->willReturnCallback(function ($argument) {
         return ['argument' => $argument['value']];
     });
     $this->arrayObjectFactory->expects($this->any())->method('create')->willReturn($componentData);
     $this->cacheConfig->expects($this->any())->method('load')->with(Manager::CACHE_ID . '_' . $componentName)->willReturn($isCached);
     $this->uiReader->expects($this->any())->method('read')->willReturn($readerData);
     $this->assertEquals($expectedResult, $this->manager->prepareData($componentName)->getData($componentName));
 }
Пример #17
0
 /**
  * Prepare the initialization data of UI components
  *
  * @param string $name
  * @return ManagerInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepareData($name)
 {
     if ($name === null || $this->hasData($name)) {
         throw new LocalizedException(new \Magento\Framework\Phrase('Initialization error component, check the ' . 'spelling of the name or the correctness of the call.'));
     }
     $this->componentsPool = $this->arrayObjectFactory->create();
     $cacheID = static::CACHE_ID . '_' . $name;
     $cachedPool = $this->cache->load($cacheID);
     if ($cachedPool === false) {
         $this->prepare($name);
         $this->cache->save($this->componentsPool->serialize(), $cacheID);
     } else {
         $this->componentsPool->unserialize($cachedPool);
     }
     $this->componentsData->offsetSet($name, $this->componentsPool);
     return $this;
 }
Пример #18
0
 /**
  * Prepare the initialization data of UI components
  *
  * @param string $name
  * @return ManagerInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function prepareData($name)
 {
     if ($name === null || $this->hasData($name)) {
         throw new LocalizedException(new \Magento\Framework\Phrase("Invalid UI Component element name: '%1'", [$name]));
     }
     $this->componentsPool = $this->arrayObjectFactory->create();
     $cacheID = static::CACHE_ID . '_' . $name;
     $cachedPool = $this->cache->load($cacheID);
     if ($cachedPool === false) {
         $this->prepare($name);
         $this->cache->save($this->componentsPool->serialize(), $cacheID);
     } else {
         $this->componentsPool->unserialize($cachedPool);
     }
     $this->componentsData->offsetSet($name, $this->componentsPool);
     $this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name)));
     return $this;
 }
Пример #19
0
 /**
  * Clear ACL instance cache
  *
  * @return void
  */
 public function clean()
 {
     $this->_acl = null;
     $this->_cache->remove($this->_cacheKey);
 }
Пример #20
0
 public function testClean()
 {
     $this->cacheConfig->expects($this->once())->method('remove')->with($this->cacheKey);
     $this->model->clean();
 }