DCache 6.x-1.x-dev
Drupal Advanced Cache
|
Go to the source code of this file.
Enumerations | |
enum | DCACHE_SESSION |
enum | DCACHE_STATIC |
enum | DCACHE_DRUPAL |
enum | DCACHE_ALL |
Functions | |
dcache_set ($cache_namespace, $cache_args, $mode=DCACHE_SESSION, $infinite=FALSE) | |
dcache_get ($cache_namespace, $mode=DCACHE_SESSION) | |
dcache_del ($cache_namespace, $mode=DCACHE_SESSION) | |
dcache_expired ($cache) | |
& | _dcache_by_ref ($cns, $mode) |
_dcache_ns ($namespace) |
Drupal Advanced Cache routines.
An API enhancement module to allow Drupal module developers to control multiple types of data caches, STATIC, SESSION or Drupal API.
The cache life can be infinite or controlled by a dcache_life_seconds variable, either globally with variable_set or if DUVar is enabled by individual user settings.
Definition in file dcache.module.
enum DCACHE_ALL |
Affect all caches.
Definition at line 35 of file dcache.module.
enum DCACHE_DRUPAL |
Store cache via Drupal cache API.
Definition at line 30 of file dcache.module.
enum DCACHE_SESSION |
Store cache in session.
Definition at line 20 of file dcache.module.
enum DCACHE_STATIC |
Store cache in static variables.
Definition at line 25 of file dcache.module.
& _dcache_by_ref | ( | $ | cns, |
$ | mode | ||
) | [private] |
Get a reference to the cached data.
$cns | String or array for the namespace value. If an array is given the values of the array are used as associative elements of the cache array tree. For example array('db', 'signatures', 'full') is the namespace for a full set of rows from the signatures table; note that 'dcache' is prepended as the first element of the array. |
$mode |
|
Definition at line 195 of file dcache.module.
Referenced by dcache_del(), dcache_get(), and dcache_set().
{ global $dcache_static; switch ($mode) { case DCACHE_SESSION: { $cache =& $_SESSION['dcache']; } break; case DCACHE_STATIC: { $cache =& $dcache_static; } break; case DCACHE_DRUPAL: { } break; } if ($mode != DCACHE_DRUPAL) { if (is_array($cns)) { switch (count($cns)) { case 0: { $ns =& $cache; } break; case 1: { $ns =& $cache[$cns[0]]; } break; case 2: { $ns =& $cache[$cns[0]][$cns[1]]; } break; case 3: { $ns =& $cache[$cns[0]][$cns[1]][$cns[2]]; } break; case 4: { $ns =& $cache[$cns[0]][$cns[1]][$cns[2]][$cns[3]]; } break; case 5: { $ns =& $cache[$cns[0]][$cns[1]][$cns[2]][$cns[3]][$cns[4]]; } break; default: { throw new Exception(t('Cache namespace elements exceed a count of 5.')); } break; } } else { $ns =& $cache[$cns]; } return $ns; } else { } }
_dcache_ns | ( | $ | namespace | ) |
Normalize module namespace for the cache.
$namespace |
|
Definition at line 251 of file dcache.module.
Referenced by dcache_del(), dcache_get(), and dcache_set().
{ $bt = debug_backtrace(); $bt = explode(DIRECTORY_SEPARATOR, $bt[1]['file']); for ($idx = 0; $idx < count($bt) - 1 && $bt[$idx] != 'modules'; $idx++) { $module = $bt[$idx + 1]; } $ns = "{$module}_"; if (is_array($namespace)) { $ns .= implode('_', $namespace); } else { $ns .= $namespace; } return $ns; }
dcache_del | ( | $ | cache_namespace, |
$ | mode = DCACHE_SESSION |
||
) |
Delete the saved data from the cache.
$cache_namespace | String or array for the namespace value. If an array is given the values of the array are used as associative elements of the cache array tree. For example array('db', 'signatures', 'full') is the namespace for a full set of rows from the signatures table; note that 'dcache' is prepended as the first element of the array. |
$mode |
|
Definition at line 138 of file dcache.module.
References _dcache_by_ref(), and _dcache_ns().
{ $ns = _dcache_ns($cache_namespace); switch ($mode) { case DCACHE_SESSION: case DCACHE_STATIC: { $svar =& _dcache_by_ref($cache_namespace, $mode); $svar = NULL; } break; case DCACHE_DRUPAL: { cache_clear_all($ns, 'cache'); } break; case DCACHE_ALL: { dcache_del($cache_namespace, DCACHE_SESSION); dcache_del($cache_namespace, DCACHE_STATIC); cache_clear_all($ns, 'cache', TRUE); } } }
dcache_expired | ( | $ | cache | ) |
Is the cache expired?
$cache | The cache array as returned by dcache_get(). |
Definition at line 166 of file dcache.module.
{ return TRUE; $life = variable_get('dcache_life_seconds', 600); if (function_exists('duvar_get')) { $life = duvar_get('dcache_life_seconds', $life); } return (isset($cache['cache_timestamp']) && (time() - $cache['cache_timestamp'] < $life)) ? FALSE : TRUE; }
dcache_get | ( | $ | cache_namespace, |
$ | mode = DCACHE_SESSION |
||
) |
Get the data from the cache.
$cache_namespace | String or array for the namespace value. If an array is given the values of the array are used as associative elements of the cache array tree. For example array('db', 'signatures', 'full') is the namespace for a full set of rows from the signatures table; note that 'dcache' is prepended as the first element of the array. |
$mode |
|
Definition at line 105 of file dcache.module.
References _dcache_by_ref(), and _dcache_ns().
{ switch ($mode) { case DCACHE_SESSION: case DCACHE_STATIC: { $svar =& _dcache_by_ref($cache_namespace, $mode); } break; case DCACHE_DRUPAL: { $ns = _dcache_ns($cache_namespace); $svar = cache_get($ns); $svar = $svar->data; } break; } return $svar; }
dcache_set | ( | $ | cache_namespace, |
$ | cache_args, | ||
$ | mode = DCACHE_SESSION , |
||
$ | infinite = FALSE |
||
) |
Save the data to the cache.
$cache_namespace | String or array for the namespace value. If an array is given the values of the array are used as associative elements of the cache array tree. For example array('db', 'signatures', 'full') is the namespace for a full set of rows from the signatures table; note that 'dcache' is prepended as the first element of the array. |
$cache_args | An associative array for the variable name and value. For example array('rows' => $rows). |
$mode |
|
$infinite |
|
Definition at line 62 of file dcache.module.
References _dcache_by_ref(), and _dcache_ns().
{ switch ($mode) { case DCACHE_SESSION: case DCACHE_STATIC: { $svar =& _dcache_by_ref($cache_namespace, $mode); } break; case DCACHE_DRUPAL: { $svar = array(); } break; } foreach ($cache_args as $arg => $val) { $svar[$arg] = $val; } $svar['cache_timestamp'] = $infinite ? 0 : time(); if ($mode == DCACHE_DRUPAL) { $ns = _dcache_ns($cache_namespace); cache_set($ns, $svar); } }