You are here

function _ctools_export_get_defaults_from_cache in Chaos Tool Suite (ctools) 7

Attempt to load default objects from cache.

We can be instructed to cache default objects by the schema. If so we cache them as an index which is a list of all default objects, and then each default object is cached individually.

Return value

Either an array of cached objects, or NULL indicating a cache rebuild is necessary.

1 call to _ctools_export_get_defaults_from_cache()
_ctools_export_get_defaults in includes/export.inc
Get export object defaults.

File

includes/export.inc, line 738
Contains code to make it easier to have exportable objects.

Code

function _ctools_export_get_defaults_from_cache($table, $export) {
  $data = cache_get('ctools_export_index:' . $table, $export['default cache bin']);
  if (!$data || !is_array($data->data)) {
    return;
  }

  // This is the perfectly valid case where there are no default objects,
  // and we have cached this state.
  if (empty($data->data)) {
    return array();
  }
  $keys = array();
  foreach ($data->data as $name) {
    $keys[] = 'ctools_export:' . $table . ':' . $name;
  }
  $data = cache_get_multiple($keys, $export['default cache bin']);

  // If any of our indexed keys missed, then we have a fail and we need to
  // rebuild.
  if (!empty($keys)) {
    return;
  }

  // Now, translate the returned cache objects to actual objects.
  $cache = array();
  foreach ($data as $cached_object) {
    $cache[$cached_object->data->{$export['key']}] = $cached_object->data;
  }
  return $cache;
}