function State::set

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::set()
  2. 10 core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::set()
  3. 9 core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::set()
  4. 8.9.x core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State::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(). If you are writing data to somewhere in addition to the cache item in ::set(), you should invalidate the cache item within a lock to ensure that another request that starts with an empty cache item does not overwrite with the previous value. For example: Drupal\Core\State\State.

Overrides CacheCollector::set

File

core/lib/Drupal/Core/State/State.php, line 97

Class

State
Provides the state system using a key value store.

Namespace

Drupal\Core\State

Code

public function set($key, $value) {
  $this->setMultiple([
    $key => $value,
  ]);
}

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