protected function CacheArray::set

Writes a value to the persistent cache immediately.

Parameters

$data: The data to write to the persistent cache.

$lock: Whether to acquire a lock before writing to cache.

1 call to CacheArray::set()
CacheArray::__destruct in drupal/core/lib/Drupal/Core/Utility/CacheArray.php
Destructs the CacheArray object.
1 method overrides CacheArray::set()
ThemeRegistry::set in drupal/core/lib/Drupal/Core/Utility/ThemeRegistry.php
Overrides CacheArray::set().

File

drupal/core/lib/Drupal/Core/Utility/CacheArray.php, line 199
Definition of CacheArray

Class

CacheArray
Provides a caching wrapper to be used in place of large array structures.

Namespace

Drupal\Core\Utility

Code

protected function set($data, $lock = TRUE) {

  // Lock cache writes to help avoid stampedes.
  // To implement locking for cache misses, override __construct().
  $lock_name = $this->cid . ':' . $this->bin;
  if (!$lock || lock()
    ->acquire($lock_name)) {
    if ($cached = cache($this->bin)
      ->get($this->cid)) {
      $data = $cached->data + $data;
    }
    cache($this->bin)
      ->set($this->cid, $data, CacheBackendInterface::CACHE_PERMANENT, $this->tags);
    if ($lock) {
      lock()
        ->release($lock_name);
    }
  }
}