コード例 #1
0
 /**
  * Listener for the Controller call
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
  * @return void
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     // Only for SubRequests
     $subRequest = $event->getRequest();
     if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     // Check if Configuration is present
     if (!($configuration = $subRequest->attributes->get('_acilia_component_fragment_cache', false))) {
         return;
     }
     // Calculate Request Key
     $key = $this->getKey($configuration, $subRequest, $this->masterRequest);
     if (!$this->enabled) {
         return;
     }
     // If content is cached, return it
     $content = $this->cache->get($key);
     if ($content !== false) {
         $fragment = '';
         if ($this->debug) {
             $fragment .= '<!-- HIT - Begin Fragment Cache for KEY: ' . $key . ' -->';
         }
         $fragment .= $content;
         if ($this->debug) {
             $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
         }
         $response = new Response($fragment);
         $event->setController(function () use($response) {
             return $response;
         });
     } else {
         $subRequest->attributes->set('_acilia_component_fragment_cache_key', $key);
     }
     return;
 }
コード例 #2
0
ファイル: BannerService.php プロジェクト: rodmen/BannerBundle
 public function getType($slug)
 {
     $key = 'Banner:Types';
     if (!is_array($this->types)) {
         $types = $this->memcache->get($key);
         if ($this->memcache->notFound()) {
             $bannerTypes = $this->doctrine->getManager()->getRepository('AciliaBannerBundle:BannerType')->findAll();
             $types = array();
             foreach ($bannerTypes as $bannerType) {
                 $types[$bannerType->getSlug()] = $bannerType->getId();
             }
             $this->memcache->set($key, $types, 1440);
         }
         $this->types = $types;
     }
     if (isset($this->types[$slug])) {
         return $this->types[$slug];
     } elseif (isset($this->types['none'])) {
         return $this->types['none'];
     } else {
         return 0;
     }
 }