function ApcuBackend::set

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Cache/ApcuBackend.php \Drupal\Core\Cache\ApcuBackend::set()

File

core/lib/Drupal/Core/Cache/ApcuBackend.php, line 165

Class

ApcuBackend
Stores cache items in the Alternative PHP Cache User Cache (APCu).

Namespace

Drupal\Core\Cache

Code

public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = []) {
  assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');
  $tags = array_unique($tags);
  $cache = new \stdClass();
  $cache->cid = $cid;
  $cache->created = round(microtime(TRUE), 3);
  $cache->expire = $expire;
  $cache->tags = implode(' ', $tags);
  $cache->checksum = $this->checksumProvider
    ->getCurrentChecksum($tags);
  // APCu serializes/unserializes any structure itself.
  $cache->serialized = 0;
  $cache->data = $data;
  // Expiration is handled by our own prepareItem(), not APCu.
  apcu_store($this->getApcuKey($cid), $cache);
}

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