public function DatabaseBackend::set

Implements Drupal\Core\Cache\CacheBackendInterface::set().

Overrides CacheBackendInterface::set

1 method overrides DatabaseBackend::set()
InstallBackend::set in drupal/core/lib/Drupal/Core/Cache/InstallBackend.php
Overrides Drupal\Core\Cache\DatabaseBackend::set().

File

drupal/core/lib/Drupal/Core/Cache/DatabaseBackend.php, line 133
Definition of Drupal\Core\Cache\DatabaseBackend.

Class

DatabaseBackend
Defines a default cache implementation.

Namespace

Drupal\Core\Cache

Code

public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {
  try {
    $flat_tags = $this
      ->flattenTags($tags);
    $checksum = $this
      ->checksumTags($flat_tags);
    $fields = array(
      'serialized' => 0,
      'created' => REQUEST_TIME,
      'expire' => $expire,
      'tags' => implode(' ', $flat_tags),
      'checksum_invalidations' => $checksum['invalidations'],
      'checksum_deletions' => $checksum['deletions'],
    );
    if (!is_string($data)) {
      $fields['data'] = serialize($data);
      $fields['serialized'] = 1;
    }
    else {
      $fields['data'] = $data;
      $fields['serialized'] = 0;
    }
    Database::getConnection()
      ->merge($this->bin)
      ->key(array(
      'cid' => $cid,
    ))
      ->fields($fields)
      ->execute();
  } catch (Exception $e) {

    // The database may not be available, so we'll ignore cache_set requests.
  }
}