Non-volatile cache storage


Detailed Description

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 cache, but otherwise the data in this cache must remain stable, as it includes unsaved changes.


Functions

 views_object_cache_get ($obj, $name, $skip_cache=FALSE)
 Get an object from the non-volatile Views cache.
 views_object_cache_set ($obj, $name, $cache)
 Store an object in the non-volatile Views cache.
 views_object_cache_clear ($obj, $name)
 Remove an object from the non-volatile Views cache.
 views_object_cache_clean ($age=NULL)
 Remove all objects in the object cache that are older than the specified age.


Function Documentation

views_object_cache_clean ( age = NULL  ) 

Remove all objects in the object cache that are older than the specified age.

Parameters:
$age The minimum age of objects to remove, in seconds. For example, 86400 is one day. Defaults to 7 days.

Definition at line 261 of file cache.inc.

00261                                                {
00262   if (empty($age)) {
00263     $age = 86400 * 7; // 7 days
00264   }
00265   db_query("DELETE FROM {views_object_cache} WHERE updated < %d", time() - $age);
00266 }

views_object_cache_clear ( obj,
name 
)

Remove an object from the non-volatile Views cache.

Parameters:
$obj A 32 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 view (or other object) being stored.

Definition at line 249 of file cache.inc.

References $name.

Referenced by views_object_cache_set(), views_ui_delete_confirm_submit(), views_ui_edit_view_form_cancel(), and views_ui_edit_view_form_submit().

00249                                                {
00250   db_query("DELETE FROM {views_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name);
00251 }

views_object_cache_get ( obj,
name,
skip_cache = FALSE 
)

Get an object from the non-volatile Views cache.

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

Parameters:
$obj A 32 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 view (or other object) being stored.
$skip_cache Skip the memory cache, meaning this must be read from the db again.
Returns:
The data that was cached.

Definition at line 208 of file cache.inc.

References $name.

00208                                                                   {
00209   static $cache = array();
00210   $key = "$obj:$name";
00211   if ($skip_cache) {
00212     unset($cache[$key]);
00213   }
00214 
00215   if (!array_key_exists($key, $cache)) {
00216     $data = db_fetch_object(db_query("SELECT * FROM {views_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name));
00217     if ($data) {
00218       $cache[$key] = unserialize($data->data);
00219     }
00220   }
00221   return isset($cache[$key]) ? $cache[$key] : NULL;
00222 }

views_object_cache_set ( obj,
name,
cache 
)

Store an object in the non-volatile Views cache.

Parameters:
$obj A 32 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 view (or other object) being stored.
$cache The object to be cached. This will be serialized prior to writing.

Definition at line 235 of file cache.inc.

References $name, and views_object_cache_clear().

00235                                                      {
00236   views_object_cache_clear($obj, $name);
00237   db_query("INSERT INTO {views_object_cache} (sid, obj, name, data, updated) VALUES ('%s', '%s', '%s', '%s', %d)", session_id(), $obj, $name, serialize($cache), time());
00238 }


Generated on Wed Jun 17 08:19:12 2009 for Views by  doxygen 1.4.7