function AliasManager::writeCache

Same name in other branches
  1. 9 core/modules/path_alias/src/AliasManager.php \Drupal\path_alias\AliasManager::writeCache()
  2. 8.9.x core/lib/Drupal/Core/Path/AliasManager.php \Drupal\Core\Path\AliasManager::writeCache()
  3. 10 core/modules/path_alias/src/AliasManager.php \Drupal\path_alias\AliasManager::writeCache()

Cache an array of the paths available on each page. We assume that aliases will be needed for the majority of these paths during subsequent requests, and load them in a single query during path alias lookup.

File

core/modules/path_alias/src/AliasManager.php, line 91

Class

AliasManager
The default alias manager implementation.

Namespace

Drupal\path_alias

Code

public function writeCache() {
    // Check if the paths for this page were loaded from cache in this request
    // to avoid writing to cache on every request.
    if ($this->cacheNeedsWriting && !empty($this->cacheKey)) {
        // Start with the preloaded path lookups, so that cached entries for other
        // languages will not be lost.
        $path_lookups = $this->preloadedPathLookups ?: [];
        foreach ($this->lookupMap as $langcode => $lookups) {
            $path_lookups[$langcode] = array_keys($lookups);
            if (!empty($this->noAlias[$langcode])) {
                $path_lookups[$langcode] = array_merge($path_lookups[$langcode], array_keys($this->noAlias[$langcode]));
            }
        }
        $twenty_four_hours = 60 * 60 * 24;
        $this->cache
            ->set($this->cacheKey, $path_lookups, $this->time
            ->getRequestTime() + $twenty_four_hours);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.