You are here

function ctools_object_cache_get in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/object-cache.inc \ctools_object_cache_get()

Get an object from the non-volatile ctools cache.

This function caches in memory as well, so that multiple calls to this will not result in multiple database reads.

Parameters

$obj: A 128 character or less string to define what kind of object is being stored; primarily this is used to prevent collisions.

$name: The name of the object being stored.

$skip_cache: Deprecated in favor of drupal_static* Skip the memory cache, meaning this must be read from the db again.

$sid: The session id, allowing someone to use Session API or their own solution; defaults to session_id().

Return value

The data that was cached.

7 calls to ctools_object_cache_get()
CtoolsObjectCache::testObjectStorage in tests/object_cache.test
ctools_ajax_sample_cache_get in ctools_ajax_sample/ctools_ajax_sample.module
Get the current object from the cache, or default.
ctools_cache_simple_cache_get in plugins/cache/simple.inc
ctools_export_ui::edit_cache_get in plugins/export_ui/ctools_export_ui.class.php
Retrieve the item currently being edited from the object cache.
ctools_stylizer_get_settings_cache in includes/stylizer.inc
Get the cached changes to a given task handler.

... See full list

2 string references to 'ctools_object_cache_get'
ctools_object_cache_clear in includes/object-cache.inc
Remove an object from the non-volatile ctools cache.
ctools_object_cache_clear_all in includes/object-cache.inc
Remove an object from the non-volatile ctools cache for all session IDs.

File

includes/object-cache.inc, line 33
The non-volatile object cache is used to store an object while it is being edited, so that we don't have to save until we're completely done. The cache should be 'cleaned' on a regular basis, meaning to remove old objects from the…

Code

function ctools_object_cache_get($obj, $name, $skip_cache = FALSE, $sid = NULL) {
  $cache =& drupal_static(__FUNCTION__, array());
  $key = "{$obj}:{$name}";
  if ($skip_cache) {
    unset($cache[$key]);
  }
  if (!$sid) {
    $sid = session_id();
  }
  if (!array_key_exists($key, $cache)) {
    $data = db_query('SELECT * FROM {ctools_object_cache} WHERE sid = :session_id AND obj = :object AND name = :name', array(
      ':session_id' => $sid,
      ':object' => $obj,
      ':name' => md5($name),
    ))
      ->fetchObject();
    if ($data) {
      $cache[$key] = unserialize($data->data);
    }
  }
  return isset($cache[$key]) ? $cache[$key] : NULL;
}