Example #1
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];
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Example #4
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;
             }
         }
     }
 }
Example #5
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);
     }
 }
Example #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;
 }
Example #7
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);
 }
Example #8
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);
     }
 }
Example #9
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);
     }
 }
Example #10
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;
 }
Example #11
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;
 }
Example #12
0
 /**
  * Save ACL object to cache
  *
  * @param \Magento\Framework\Acl $acl
  * @return void
  */
 public function save(\Magento\Framework\Acl $acl)
 {
     $this->_acl = $acl;
     $this->_cache->save(serialize($acl), $this->_cacheKey);
 }