Commit 9f0005d5 authored by effulgentsia's avatar effulgentsia

Issue #2582219 by catch, Berdir: Preload Cache in AliasManager can get huge

parent ad81d250
......@@ -145,10 +145,8 @@ public function writeCache() {
}
}
if (!empty($path_lookups)) {
$twenty_four_hours = 60 * 60 * 24;
$this->cache->set($this->cacheKey, $path_lookups, $this->getRequestTime() + $twenty_four_hours);
}
$twenty_four_hours = 60 * 60 * 24;
$this->cache->set($this->cacheKey, $path_lookups, $this->getRequestTime() + $twenty_four_hours);
}
}
......@@ -175,7 +173,6 @@ public function getPathByAlias($alias, $langcode = NULL) {
// Look for path in storage.
if ($path = $this->storage->lookupPathSource($alias, $langcode)) {
$this->lookupMap[$langcode][$path] = $alias;
$this->cacheNeedsWriting = TRUE;
return $path;
}
......@@ -216,8 +213,13 @@ public function getAliasByPath($path, $langcode = NULL) {
// happens if a cache key has been set.
if ($this->preloadedPathLookups === FALSE) {
$this->preloadedPathLookups = array();
if ($this->cacheKey && $cached = $this->cache->get($this->cacheKey)) {
$this->preloadedPathLookups = $cached->data;
if ($this->cacheKey) {
if ($cached = $this->cache->get($this->cacheKey)) {
$this->preloadedPathLookups = $cached->data;
}
else {
$this->cacheNeedsWriting = TRUE;
}
}
}
......@@ -242,14 +244,12 @@ public function getAliasByPath($path, $langcode = NULL) {
// Try to load alias from storage.
if ($alias = $this->storage->lookupPathAlias($path, $langcode)) {
$this->lookupMap[$langcode][$path] = $alias;
$this->cacheNeedsWriting = TRUE;
return $alias;
}
// We can't record anything into $this->lookupMap because we didn't find any
// aliases for this path. Thus cache to $this->noAlias.
$this->noAlias[$langcode][$path] = TRUE;
$this->cacheNeedsWriting = TRUE;
return $path;
}
......
......@@ -339,14 +339,10 @@ public function testGetAliasByPathCachedMissLanguage() {
// Call it twice to test the static cache.
$this->assertEquals($alias, $this->aliasManager->getAliasByPath($path));
// This needs to write out the cache.
$expected_new_cache = array(
$cached_language->getId() => array($path),
$language->getId() => array($path),
);
$this->cache->expects($this->once())
->method('set')
->with($this->cacheKey, $expected_new_cache, (int) $_SERVER['REQUEST_TIME'] + (60 * 60 * 24));
// There is already a cache entry, so this should not write out to the
// cache.
$this->cache->expects($this->never())
->method('set');
$this->aliasManager->writeCache();
}
......@@ -441,13 +437,10 @@ public function testGetAliasByPathUncachedMissNoAlias() {
// Call it twice to test the static cache.
$this->assertEquals($path, $this->aliasManager->getAliasByPath($path));
// This needs to write out the cache.
$expected_new_cache = array(
$language->getId() => array($cached_path, $path),
);
$this->cache->expects($this->once())
->method('set')
->with($this->cacheKey, $expected_new_cache, (int) $_SERVER['REQUEST_TIME'] + (60 * 60 * 24));
// There is already a cache entry, so this should not write out to the
// cache.
$this->cache->expects($this->never())
->method('set');
$this->aliasManager->writeCache();
}
......@@ -533,13 +526,10 @@ public function testGetAliasByPathUncachedMissWithAlias() {
// Call it twice to test the static cache.
$this->assertEquals($new_alias, $this->aliasManager->getAliasByPath($path));
// This needs to write out the cache.
$expected_new_cache = array(
$language->getId() => array($cached_path, $path, $cached_no_alias_path),
);
$this->cache->expects($this->once())
->method('set')
->with($this->cacheKey, $expected_new_cache, (int) $_SERVER['REQUEST_TIME'] + (60 * 60 * 24));
// There is already a cache entry, so this should not write out to the
// cache.
$this->cache->expects($this->never())
->method('set');
$this->aliasManager->writeCache();
}
......
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