function CacheCollector::set

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/CacheCollector.php \Drupal\Core\Cache\CacheCollector::set()
  2. 10 core/lib/Drupal/Core/Cache/CacheCollector.php \Drupal\Core\Cache\CacheCollector::set()
  3. 11.x core/lib/Drupal/Core/Cache/CacheCollector.php \Drupal\Core\Cache\CacheCollector::set()

Implements \Drupal\Core\Cache\CacheCollectorInterface::set().

This is not persisted by default. In practice this means that setting a value will only apply while the object is in scope and will not be written back to the persistent cache. This follows a similar pattern to static vs. persistent caching in procedural code. Extending classes may wish to alter this behavior, for example by adding a call to persist().

Overrides CacheCollectorInterface::set

1 call to CacheCollector::set()
CacheCollectorHelper::set in core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php
Implements \Drupal\Core\Cache\CacheCollectorInterface::set().
1 method overrides CacheCollector::set()
CacheCollectorHelper::set in core/tests/Drupal/Tests/Core/Cache/CacheCollectorHelper.php
Implements \Drupal\Core\Cache\CacheCollectorInterface::set().

File

core/lib/Drupal/Core/Cache/CacheCollector.php, line 162

Class

CacheCollector
Default implementation for CacheCollectorInterface.

Namespace

Drupal\Core\Cache

Code

public function set($key, $value) {
    $this->lazyLoadCache();
    $this->storage[$key] = $value;
    // The key might have been marked for deletion.
    unset($this->keysToRemove[$key]);
    $this->invalidateCache();
}

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