You are here

protected function ThemeRegistry::updateCache in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Utility/ThemeRegistry.php \Drupal\Core\Utility\ThemeRegistry::updateCache()

Writes a value to the persistent cache immediately.

Parameters

bool $lock: (optional) Whether to acquire a lock before writing to cache. Defaults to TRUE.

Overrides CacheCollector::updateCache

1 call to ThemeRegistry::updateCache()
ThemeRegistry::__construct in core/lib/Drupal/Core/Utility/ThemeRegistry.php
Constructs a ThemeRegistry object.

File

core/lib/Drupal/Core/Utility/ThemeRegistry.php, line 136

Class

ThemeRegistry
Builds the run-time theme registry.

Namespace

Drupal\Core\Utility

Code

protected function updateCache($lock = TRUE) {
  if (!$this->persistable) {
    return;
  }

  // @todo: Is the custom implementation necessary?
  $data = [];
  foreach ($this->keysToPersist as $offset => $persist) {
    if ($persist) {
      $data[$offset] = $this->storage[$offset];
    }
  }
  if (empty($data)) {
    return;
  }
  $lock_name = $this->cid . ':' . __CLASS__;
  if (!$lock || $this->lock
    ->acquire($lock_name)) {
    if ($cached = $this->cache
      ->get($this->cid)) {

      // Use array merge instead of union so that filled in values in $data
      // overwrite empty values in the current cache.
      $data = array_merge($cached->data, $data);
    }
    else {
      $registry = $this
        ->initializeRegistry();
      $data = array_merge($registry, $data);
    }
    $this->cache
      ->set($this->cid, $data, Cache::PERMANENT, $this->tags);
    if ($lock) {
      $this->lock
        ->release($lock_name);
    }
  }
}