Commit f4d2f16f authored by webchick's avatar webchick

Issue #1891692 by katbailey: Fixed AliasManagerCacheDecorator won't work...

Issue #1891692 by katbailey: Fixed AliasManagerCacheDecorator won't work correctly with subrequests.
parent 956b110a
......@@ -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);
}
/**
......
......@@ -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);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment