Instantiates and statically caches the correct class for a cache bin.
By default, this returns an instance of the Drupal\Core\Cache\DatabaseBackend class.
Classes implementing Drupal\Core\Cache\CacheBackendInterface can register themselves both as a default implementation and for specific bins.
$bin: The cache bin for which the cache object should be returned, defaults to 'cache'.
Drupal\Core\Cache\CacheBackendInterface The cache object associated with the specified bin.
Drupal\Core\Cache\CacheBackendInterface
function cache($bin = 'cache') {
// Use the advanced drupal_static() pattern, since this is called very often.
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['cache'] =& drupal_static(__FUNCTION__, array());
}
$cache_objects =& $drupal_static_fast['cache'];
// Temporary backwards compatibiltiy layer, allow old style prefixed cache
// bin names to be passed as arguments.
$bin = str_replace('cache_', '', $bin);
if (!isset($cache_objects[$bin])) {
$cache_objects[$bin] = CacheFactory::get($bin);
}
return $cache_objects[$bin];
}