function MemoryBackend::set

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::set()
  2. 10 core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::set()
  3. 8.9.x core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::set()
1 method overrides MemoryBackend::set()
MemoryCache::set in core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php
Stores data in the persistent cache.

File

core/lib/Drupal/Core/Cache/MemoryBackend.php, line 102

Class

MemoryBackend
Defines a memory cache implementation.

Namespace

Drupal\Core\Cache

Code

public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
  assert(Inspector::assertAllStrings($tags), 'Cache Tags must be strings.');
  $tags = array_unique($tags);
  // Sort the cache tags so that they are stored consistently in the database.
  sort($tags);
  $this->cache[$cid] = (object) [
    'cid' => $cid,
    'data' => serialize($data),
    'created' => $this->getRequestTime(),
    'expire' => $expire,
    'tags' => $tags,
  ];
}

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