function drush_cache_set_prepare_data

8.0.x cache.drush.inc drush_cache_set_prepare_data($data)
7.x cache.drush.inc drush_cache_set_prepare_data($data)
master cache.drush.inc drush_cache_set_prepare_data($data)
1 call to drush_cache_set_prepare_data()
drush_cache_command_set in commands/core/cache.drush.inc
Set an object in the cache.

File

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

Code

function drush_cache_set_prepare_data($data) {
  if ($data == '-') {
    $data = file_get_contents("php://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 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."));
    }
  }

  return $data;
}