diff --git a/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php b/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php index ae5c8bca4fd0d72dddf49d9daef61baa7445bcdf..01264c2dd2512b7483194e207ab47986a79b09d5 100644 --- a/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php +++ b/core/lib/Drupal/Core/CacheDecorator/AliasManagerCacheDecorator.php @@ -26,11 +26,11 @@ class AliasManagerCacheDecorator implements CacheDecoratorInterface, AliasManage protected $cache; /** - * Stack of request paths for use as cids when caching system paths. + * The cache key to use when caching system paths. * - * @var array + * @var string */ - protected $cacheKeys = array(); + protected $cacheKey; /** * Holds an array of previously cached paths based on a request path. @@ -58,7 +58,7 @@ public function __construct(AliasManagerInterface $alias_manager, CacheBackendIn * Implements \Drupal\Core\CacheDecorator\CacheDecoratorInterface::setCacheKey(). */ public function setCacheKey($key) { - $this->cacheKeys[] = $key; + $this->cacheKey = $key; } /** @@ -73,15 +73,11 @@ public function writeCache() { $path_lookups = $this->getPathLookups(); // Check if the system paths for this page were loaded from cache in this // request to avoid writing to cache on every request. - if ($this->cacheNeedsWriting && !empty($path_lookups) && !empty($this->cacheKeys)) { - // Use the system path of the current request for the cache ID (cid). - $cid = end($this->cacheKeys); + if ($this->cacheNeedsWriting && !empty($path_lookups) && !empty($this->cacheKey)) { // Set the path cache to expire in 24 hours. $expire = REQUEST_TIME + (60 * 60 * 24); - $this->cache->set($cid, $path_lookups, $expire); + $this->cache->set($this->cacheKey, $path_lookups, $expire); } - // We are at the end of the request, so pop off the last request path. - array_pop($this->cacheKeys); } /** diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 8f0359d3cef3ddcf9cb8a640de1e5147f5f4b41f..be0e779f05401e66d44cb6898662ce43047b0671 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -8,6 +8,7 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\CacheDecorator\AliasManagerCacheDecorator; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\PostResponseEvent; @@ -35,7 +36,11 @@ public function onKernelRequestPathResolve(GetResponseEvent $event) { $path = $this->extractPath($request); $path = $this->aliasManager->getSystemPath($path); $this->setPath($request, $path); - $this->aliasManager->setCacheKey($path); + // If this is the master request, set the cache key for the caching of all + // system paths looked up during the request. + if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { + $this->aliasManager->setCacheKey($path); + } } /**