2006-06-14 14:01:12 +00:00
|
|
|
<?php
|
|
|
|
|
2009-06-16 23:48:09 +00:00
|
|
|
/**
|
2011-12-05 12:52:27 +00:00
|
|
|
* @file
|
|
|
|
* Functions and interfaces for cache handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates and statically caches the correct class for a cache bin.
|
2009-06-16 23:48:09 +00:00
|
|
|
*
|
2012-02-01 03:22:12 +00:00
|
|
|
* By default, this returns an instance of the Drupal\Core\Cache\DatabaseBackend
|
2012-01-13 03:19:33 +00:00
|
|
|
* class.
|
|
|
|
*
|
2012-02-01 03:22:12 +00:00
|
|
|
* Classes implementing Drupal\Core\Cache\CacheBackendInterface can register
|
|
|
|
* themselves both as a default implementation and for specific bins.
|
2009-06-16 23:48:09 +00:00
|
|
|
*
|
|
|
|
* @param $bin
|
2011-09-07 18:38:31 +00:00
|
|
|
* The cache bin for which the cache object should be returned, defaults to
|
|
|
|
* 'cache'.
|
2011-12-05 12:52:27 +00:00
|
|
|
*
|
2012-02-01 03:22:12 +00:00
|
|
|
* @return Drupal\Core\Cache\CacheBackendInterface
|
2009-12-04 16:31:04 +00:00
|
|
|
* The cache object associated with the specified bin.
|
2011-12-05 12:52:27 +00:00
|
|
|
*
|
2012-02-01 03:22:12 +00:00
|
|
|
* @see Drupal\Core\Cache\CacheBackendInterface
|
2009-06-16 23:48:09 +00:00
|
|
|
*/
|
2011-09-07 18:38:31 +00:00
|
|
|
function cache($bin = 'cache') {
|
|
|
|
// Temporary backwards compatibiltiy layer, allow old style prefixed cache
|
|
|
|
// bin names to be passed as arguments.
|
|
|
|
$bin = str_replace('cache_', '', $bin);
|
|
|
|
|
2011-10-02 10:43:40 +00:00
|
|
|
// We do not use drupal_static() here because we do not want to change the
|
|
|
|
// storage of a cache bin mid-request.
|
|
|
|
static $cache_objects;
|
2009-06-16 23:48:09 +00:00
|
|
|
if (!isset($cache_objects[$bin])) {
|
2009-09-01 20:43:21 +00:00
|
|
|
$class = variable_get('cache_class_' . $bin);
|
|
|
|
if (!isset($class)) {
|
2012-02-01 03:22:12 +00:00
|
|
|
$class = variable_get('cache_default_class', 'Drupal\Core\Cache\DatabaseBackend');
|
2009-06-16 23:48:09 +00:00
|
|
|
}
|
|
|
|
$cache_objects[$bin] = new $class($bin);
|
|
|
|
}
|
|
|
|
return $cache_objects[$bin];
|
|
|
|
}
|
|
|
|
|
2006-06-14 14:01:12 +00:00
|
|
|
/**
|
2011-12-30 06:00:36 +00:00
|
|
|
* Expires data from the block and page caches.
|
2006-06-14 14:01:12 +00:00
|
|
|
*/
|
2011-12-30 06:00:36 +00:00
|
|
|
function cache_clear_all() {
|
|
|
|
// @todo: remove before release.
|
|
|
|
if (func_get_args()) {
|
|
|
|
throw new Exception(t('cache_clear_all() no longer takes arguments, use cache() instead.'));
|
2006-08-30 08:46:17 +00:00
|
|
|
}
|
2011-12-30 06:00:36 +00:00
|
|
|
// Clear the block cache first, so stale data will
|
|
|
|
// not end up in the page cache.
|
|
|
|
if (module_exists('block')) {
|
|
|
|
cache('block')->expire();
|
|
|
|
}
|
|
|
|
cache('page')->expire();
|
2009-09-13 17:49:51 +00:00
|
|
|
}
|