1.14.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.12.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.10.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.11.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.13.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.7.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.8.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $expire = CACHE_PERMANENT)
1.9.x cache_database.inc BackdropDatabaseCache::set($cid, $data, $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($cid, $data, $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.
  }
}