You are here

function ctools_object_cache_set in Chaos Tool Suite (ctools) 7

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

Store an object in the non-volatile ctools cache.

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.

$cache: The object to be cached. This will be serialized prior to writing.

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

7 calls to ctools_object_cache_set()
CtoolsObjectCache::testObjectStorage in tests/object_cache.test
ctools_ajax_sample_cache_set in ctools_ajax_sample/ctools_ajax_sample.module
Store our little cache so that we can retain data from form to form.
ctools_cache_simple_cache_set in plugins/cache/simple.inc
ctools_export_ui::edit_cache_set_key in plugins/export_ui/ctools_export_ui.class.php
ctools_stylizer_set_settings_cache in includes/stylizer.inc
Store changes to a task handler in the object cache.

... See full list

File

includes/object-cache.inc, line 71
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_set($obj, $name, $cache, $sid = NULL) {

  // Store the CTools session id in the user session to force a
  // session for anonymous users in Drupal 7 and Drupal 6 Pressflow.
  // see http://drupal.org/node/562374, http://drupal.org/node/861778
  if (empty($GLOBALS['user']->uid) && empty($_SESSION['ctools_session_id'])) {
    $_SESSION['ctools_hold_session'] = TRUE;
  }
  ctools_object_cache_clear($obj, $name, $sid);
  if (!$sid) {
    $sid = session_id();
  }
  db_insert('ctools_object_cache')
    ->fields(array(
    'sid' => $sid,
    'obj' => $obj,
    'name' => md5($name),
    'data' => serialize($cache),
    'updated' => REQUEST_TIME,
  ))
    ->execute();
}