Ejemplo n.º 1
0
 /**
  * This event is executed before every route is executed in the dispatcher.
  *
  * @param Event      $event      Event object.
  * @param Dispatcher $dispatcher Dispatcher object.
  *
  * @return bool
  */
 public function beforeExecuteRoute($event, $dispatcher)
 {
     // Parse the annotations in the method currently executed.
     $annotations = $this->annotations->getMethod($dispatcher->getActiveController(), $dispatcher->getActiveMethod());
     // Check if the method has an annotation 'Cache'.
     if ($annotations->has('Cache')) {
         // The method has the annotation 'Cache'.
         /** @var \Phalcon\Annotations\Annotation $annotation */
         $annotation = $annotations->get('Cache');
         // Get the lifetime.
         $lifetime = $annotation->getNamedArgument('lifetime');
         $options = ['lifetime' => $lifetime];
         // Check if there is a user defined cache key.
         if ($annotation->hasNamedArgument('key')) {
             $options['key'] = $annotation->getNamedArgument('key');
         }
         // Enable the cache for the current method.
         $this->view->cache($options);
     }
     return !$event->isStopped();
 }