1.20.x cache_database.inc BackdropDatabaseCache::set(string $cid, $data, int $expire = CACHE_PERMANENT)

Implements BackdropCacheInterface::set().

Overrides BackdropCacheInterface::set

File

drivers/cache_database/cache_database.inc, line 96

Class

BackdropDatabaseCache
Defines a default cache implementation.

Code

function set(string $cid, $data, int $expire = CACHE_PERMANENT) {
  $fields = array(
    'serialized' => 0,
    'created' => REQUEST_TIME,
    'expire' => $expire,
  );
  if (!is_string($data)) {
    $fields['data'] = serialize($data);
    $fields['serialized'] = 1;
  }
  else {
    $fields['data'] = $data;
    $fields['serialized'] = 0;
  }

  try {
    db_merge($this->bin)
      ->key(array('cid' => $cid))
      ->fields($fields)
      ->execute();
  }
  catch (Exception $e) {
    // The database may not be available, so we'll ignore these calls.
  }
}