setCacheKey example


  public function onKernelController(ControllerEvent $event) {
    // Set the cache key on the alias manager cache decorator.     if ($event->isMainRequest() && $this->workspaceManager->hasActiveWorkspace()) {
      $cache_key = $this->workspaceManager->getActiveWorkspace()->id() . ':' . rtrim($this->currentPath->getPath($event->getRequest()), '/');
      $this->aliasManager->setCacheKey($cache_key);
    }
  }

  /** * Adds the active workspace as a cache key part to the route provider. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * An event object. */
  public function onKernelRequest(RequestEvent $event) {
    if ($this->workspaceManager->hasActiveWorkspace() && $this->routeProvider instanceof CacheableRouteProviderInterface) {
      

  public function testGetAliasByPathNoMatch() {
    $path_part1 = $this->randomMachineName();
    $path_part2 = $this->randomMachineName();
    $path = '/' . $path_part1 . '/' . $path_part2;

    $language = $this->setUpCurrentLanguage();

    $this->aliasManager->setCacheKey($this->path);

    $this->aliasWhitelist->expects($this->any())
      ->method('get')
      ->with($path_part1)
      ->willReturn(TRUE);

    $this->aliasRepository->expects($this->once())
      ->method('lookupBySystemPath')
      ->with($path$language->getId())
      ->willReturn(NULL);

    
/** * Sets the cache key on the alias manager cache decorator. * * KernelEvents::CONTROLLER is used in order to be executed after routing. * * @param \Symfony\Component\HttpKernel\Event\ControllerEvent $event * The Event to process. */
  public function onKernelController(ControllerEvent $event) {
    // Set the cache key on the alias manager cache decorator.     if ($event->isMainRequest()) {
      $this->aliasManager->setCacheKey(rtrim($this->currentPath->getPath($event->getRequest()), '/'));
    }
  }

  /** * Ensures system paths for the request get cached. */
  public function onKernelTerminate(TerminateEvent $event) {
    $this->aliasManager->writeCache();
  }

  /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */
Home | Imprint | This part of the site doesn't use cookies.