function drush_cache_command_set

8.0.x cache.drush.inc drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = NULL, $tags = array())
6.x cache.drush.inc drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = CACHE_PERMANENT)
7.x cache.drush.inc drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = NULL, $tags = array())
5.x cache.drush.inc drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = CACHE_PERMANENT)
master cache.drush.inc drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = NULL, $tags = array())

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.

1 string reference to 'drush_cache_command_set'
cache_drush_command in commands/core/cache.drush.inc
Implementation of hook_drush_command().

File

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

Code

function drush_cache_command_set($cid = NULL, $data = '', $bin = NULL, $expire = CACHE_PERMANENT) {
  if (!$bin) {
    $bin = 'cache';
  }

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

  // Convert the "expire" argument to a valid value for Drupal's cache_set().
  if ($expire == 'CACHE_TEMPORARY') {
    $expire = CACHE_TEMPORARY;
  }
  if ($expire == 'CACHE_PERMANENT') {
    $expire = CACHE_PERMANENT;
  }

  // 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 might be an object.
    if (is_object($data) && $data->data) {
      $data = $data->data;
    }
    // But $data returned from `drush cache-get --format=json` will be an array.
    elseif (is_array($data) && isset($data['data'])) {
      $data = $data['data'];
    }
    else {
      // If $data is neither object nor array and cache-get was specified, then
      // there is a problem.
      return drush_set_error('CACHE_INVALID_FORMAT', dt("'cache-get' was specified as an option, but the data is neither an object or an array."));
    }
  }

  cache_set($cid, $data, $bin, $expire);
}