function drush_cache_set

8.0.x cache.inc drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT)
6.x cache.inc drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT)
7.x cache.inc drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT)
4.x cache.drush.inc drush_cache_set($cid = NULL, $data = '', $bin = NULL, $expire = CACHE_PERMANENT)
5.x cache.inc drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT)
master cache.inc drush_cache_set($cid, $data, $bin = 'default', $expire = DRUSH_CACHE_PERMANENT)

Set an object in the cache.

Parameters

$cid: The cache ID of the object to fetch.

$data: The data to save to the cache, or '-' to read from STDIN.

$bin: Optional parameter to specify a specific bin to fetch from.

$expire: Optional parameter to specify the expiry of the cached object.

File

commands/core/cache.drush.inc, line 140

Code

function drush_cache_set($cid = NULL, $data = '', $bin = NULL, $expire = CACHE_PERMANENT) {
  if (!$cid) {
    drush_log(dt('You must specify a cache id to set.'), 'error');
    return;
  }

  if ($data === '') {
    drush_log(dt('The data to set must be non-empty.'), 'error');
    return;
  }

  if (!$bin) {
    $bin = 'cache';
  }

  if ($data == '-') {
    $data = stream_get_contents(STDIN);
  }

  // Now, we parse the object.
  switch (drush_get_option('format', 'string')) {
    case 'json':
      $data = drush_json_decode($data);
      break;
  }

  if (drush_get_option('cache-get')) {
    $data = $data->data;
  }

  switch (drush_drupal_major_version()) {
    case 5:
      cache_set($cid, $bin, $data, $expire);
      break;
    case 6:
    case 7:
    default:
      cache_set($cid, $data, $bin, $expire);
  }
}