You are here

protected function DatabaseRawBackend::doSetMultiple in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/Cache/DatabaseRawBackend.php \Drupal\supercache\Cache\DatabaseRawBackend::doSetMultiple()

Stores multiple items in the persistent cache.

Parameters

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

See also

\Drupal\Core\Cache\CacheRawBackendInterface::setMultiple()

1 call to DatabaseRawBackend::doSetMultiple()
DatabaseRawBackend::setMultiple in src/Cache/DatabaseRawBackend.php
Store multiple items in the persistent cache.

File

src/Cache/DatabaseRawBackend.php, line 245
Contains \Drupal\supercache\Cache\DatabaseRawBackend.

Class

DatabaseRawBackend
Defines a default cache implementation.

Namespace

Drupal\supercache\Cache

Code

protected function doSetMultiple(array $items) {
  $values = array();
  foreach ($items as $cid => $item) {
    $item += array(
      'expire' => CacheRawBackendInterface::CACHE_PERMANENT,
    );
    $values[] = $this
      ->prepareStorage($cid, $item['data'], $item['expire']);
  }

  // Use an upsert query which is atomic and optimized for multiple-row
  // merges.
  $query = $this->connection
    ->upsert($this->bin)
    ->key('cid')
    ->fields(array(
    'cid',
    'expire',
    'data_serialized',
    'data_string',
    'data_int',
    'data_float',
    'storage',
  ));
  foreach ($values as $fields) {

    // Only pass the values since the order of $fields matches the order of
    // the insert fields. This is a performance optimization to avoid
    // unnecessary loops within the method.
    $query
      ->values(array_values($fields));
  }
  $query
    ->execute();
}