You are here

public function MemcachedBackend::setMultiple in Memcache Storage 8

Store multiple items in the persistent cache.

Parameters

array $items: An array of cache items, keyed by cid. In the form:

$items = array(
  $cid => array(
    // Required, will be automatically serialized if not a string.
    'data' => $data,
    // Optional, defaults to CacheBackendInterface::CACHE_PERMANENT.
    'expire' => CacheBackendInterface::CACHE_PERMANENT,
    // (optional) The cache tags for this item, see CacheBackendInterface::set().
    'tags' => array(),
  ),
);

Overrides CacheBackendInterface::setMultiple

1 call to MemcachedBackend::setMultiple()
MemcachedBackend::set in src/MemcachedBackend.php
Stores data in the persistent cache.

File

src/MemcachedBackend.php, line 127

Class

MemcachedBackend

Namespace

Drupal\memcache_storage

Code

public function setMultiple(array $items) {
  $values = array();
  foreach ($items as $cid => $item) {

    // All items should have expiration data and initialized tags value.
    $item += array(
      'expire' => CacheBackendInterface::CACHE_PERMANENT,
      'tags' => array(),
    );
    assert('\\Drupal\\Component\\Assertion\\Inspector::assertAllStrings($item[\'tags\'])', 'Cache Tags must be strings.');

    // Organize tags.
    $item['tags'] = array_unique($item['tags']);
    sort($item['tags']);

    // Create a new object which will be passed to the memcached server for
    // storage.
    $value = new \stdClass();
    $value->cid = $cid;
    $value->expire = $item['expire'];
    $value->created = round(microtime(TRUE), 3);
    $value->tags = $item['tags'];
    $value->checksum = $this->checksumProvider
      ->getCurrentChecksum($item['tags']);
    $value->data = $item['data'];
    $values[] = $value;
  }
  if (empty($values)) {
    return TRUE;
  }

  // Handover set operation to DrupalMemcache(d) object.
  return $this->memcached
    ->setMulti($values, $this->bin);
}