function State::set

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

Overrides CacheCollector::set

File

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

Class

State
Provides the state system using a key value store.

Namespace

Drupal\Core\State

Code

public function set($key, $value) {
    if (isset(self::$deprecatedState[$key])) {
        // phpcs:ignore Drupal.Semantics.FunctionTriggerError
        @trigger_error(self::$deprecatedState[$key]['message'], E_USER_DEPRECATED);
        $key = self::$deprecatedState[$key]['replacement'];
    }
    $this->keyValueStore
        ->set($key, $value);
    // If another request had a cache miss before this request, and also hasn't
    // written to cache yet, then it may already have read this value from the
    // database and could write that value to the cache to the end of the
    // request. To avoid this race condition, write to the cache immediately
    // after calling parent::set(). This allows the race condition detection in
    // CacheCollector::set() to work.
    parent::set($key, $value);
    $this->persist($key);
    static::updateCache();
}

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