W3cubDocs

/Drupal 8

protected function 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);
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Utility!ThemeRegistry.php/function/ThemeRegistry::updateCache/8.1.x