1 cache.inc cache($bin = 'cache')

Instantiates and statically caches the correct class for a cache bin.

By default, this returns an instance of the BackdropDatabaseCache class. Classes implementing BackdropCacheInterface can register themselves both as a default implementation and for specific bins.

Parameters

$bin: The cache bin for which the cache object should be returned, defaults to 'cache'.

Return value

BackdropCacheInterface: The cache object associated with the specified bin.

See also

BackdropCacheInterface

File

core/includes/cache.inc, line 23
Functions and interfaces for cache handling.

Code

function cache($bin = 'cache') {
  // Temporary backwards compatibility layer, allow old style prefixed cache
  // bin names to be passed as arguments.
  $bin = str_replace('cache_', '', $bin);

  // We do not use backdrop_static() here because we do not want to change the
  // storage of a cache bin mid-request.
  static $cache_objects;
  if (!isset($cache_objects[$bin])) {
    $class = settings_get('cache_class_' . $bin);
    if (!isset($class)) {
      $class = settings_get('cache_default_class', 'BackdropDatabaseCache');
    }
    $cache_objects[$bin] = new $class($bin);
  }
  return $cache_objects[$bin];
}