FileCacheFactory::get

public static FileCacheFactory::get($collection, $default_configuration = [])

Instantiates a FileCache object for a given collection identifier.

Parameters

string $collection: The collection identifier for this FileCache.

array $default_configuration: (optional) The default configuration for this FileCache collection. This can be used to e.g. specify default usage of a FileCache class.

Return value

\Drupal\Component\FileCache\FileCacheInterface The initialized FileCache object.

File

core/lib/Drupal/Component/FileCache/FileCacheFactory.php, line 41

Class

FileCacheFactory
Creates a FileCache object.

Namespace

Drupal\Component\FileCache

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public static function get($collection, $default_configuration = []) {
  // If there is a special key in the configuration, disable FileCache completely.
  if (!empty(static::$configuration[static::DISABLE_CACHE])) {
    return new NullFileCache('', '');
  }
 
  $configuration = [];
 
  // Check for a collection specific setting first.
  if (isset(static::$configuration[$collection])) {
    $configuration += static::$configuration[$collection];
  }
  // Then check if a default configuration has been provided.
  if (!empty($default_configuration)) {
    $configuration += $default_configuration;
  }
  // Last check if a default setting has been provided.
  if (isset(static::$configuration['default'])) {
    $configuration += static::$configuration['default'];
  }
 
  // Ensure that all properties are set.
  $fallback_configuration = [
    'class' => '\Drupal\Component\FileCache\FileCache',
    'collection' => $collection,
    'cache_backend_class' => NULL,
    'cache_backend_configuration' => [],
  ];
 
  $configuration = $configuration + $fallback_configuration;
 
  $class = $configuration['class'];
  return new $class(static::getPrefix(), $configuration['collection'], $configuration['cache_backend_class'], $configuration['cache_backend_configuration']);
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.