示例#1
0
 /**
  * Overriden with page detection from URL
  * @return Localization
  */
 public function getLocalization()
 {
     $data = parent::getLocalization();
     if (empty($data)) {
         $data = $this->detectRequestPageLocalization();
         $this->setLocalization($data);
     }
     return $data;
 }
示例#2
0
 /**
  * Caches block responses
  */
 protected function cacheBlockResponses()
 {
     $cacheRequests = $this->blockCacheRequests;
     $localization = $this->pageRequest->getLocalization();
     $logger = $this->container->getLogger();
     $cache = $this->container->getCache();
     $this->iterateBlocks(function (Block $block, BlockController $controller) use(&$cacheRequests, $localization, $cache, $logger) {
         $blockId = $block->getId();
         if (!isset($cacheRequests[$blockId])) {
             return;
         }
         $cacheConfig = $cacheRequests[$blockId];
         $response = $controller->getResponse();
         $context = $response->getContext();
         try {
             $cache->store('block_cache', $cacheConfig->getCacheKey($localization, $block, $context), serialize($response), time(), $cacheConfig->getLifetime());
         } catch (\Exception $e) {
             $logger->error(sprintf("Failed to store cache for [%s], got exception [%s]", get_class($controller), $e->getMessage()));
         }
     });
 }