ThemeRegistry::updateCache

protected ThemeRegistry::updateCache($lock = TRUE)

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

File

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

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 = array();
  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);
    }
  }
}
doc_Drupal
2016-10-29 09:48:20
Comments
Leave a Comment

Please login to continue.