1.20.x cache.inc cache(string $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

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

Code

function cache(string $bin = 'cache') {
  // Temporary backwards compatibiltiy 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];
}