function Settings::getApcuPrefix

Same name in other branches
  1. 9 core/lib/Drupal/Core/Site/Settings.php \Drupal\Core\Site\Settings::getApcuPrefix()
  2. 8.9.x core/lib/Drupal/Core/Site/Settings.php \Drupal\Core\Site\Settings::getApcuPrefix()
  3. 10 core/lib/Drupal/Core/Site/Settings.php \Drupal\Core\Site\Settings::getApcuPrefix()

Generates a prefix for APCu user cache keys.

A standardized prefix is useful to allow visual inspection of an APCu user cache. By default, this method will produce a unique prefix per site using the hash salt. If the setting 'apcu_ensure_unique_prefix' is set to FALSE then if the caller does not provide a $site_path only the Drupal root will be used. This allows tests to use the same prefix ensuring that the number of APCu items created during a full test run is kept to a minimum. Additionally, if a multi site implementation does not use site specific module directories setting apcu_ensure_unique_prefix would allow the sites to share APCu cache items.

Parameters

string $identifier: An identifier for the prefix. For example, 'class_loader' or 'cache_backend'.

string $root: The app root.

string $site_path: (optional) The site path. Defaults to an empty string.

Return value

string The prefix for APCu user cache keys.

See also

https://www.drupal.org/project/drupal/issues/2926309

3 calls to Settings::getApcuPrefix()
ApcuBackendFactory::__construct in core/lib/Drupal/Core/Cache/ApcuBackendFactory.php
Constructs an ApcuBackendFactory object.
DrupalKernel::boot in core/lib/Drupal/Core/DrupalKernel.php
Boots the current kernel.
KernelTestBase::initFileCache in core/tests/Drupal/KernelTests/KernelTestBase.php
Initializes the FileCache component.

File

core/lib/Drupal/Core/Site/Settings.php, line 204

Class

Settings
Read only settings that are initialized with the class.

Namespace

Drupal\Core\Site

Code

public static function getApcuPrefix($identifier, $root, $site_path = '') {
    if (static::get('apcu_ensure_unique_prefix', TRUE)) {
        return 'drupal.' . $identifier . '.' . \Drupal::VERSION . '.' . static::get('deployment_identifier') . '.' . hash_hmac('sha256', $identifier, static::get('hash_salt') . '.' . $root . '/' . $site_path);
    }
    return 'drupal.' . $identifier . '.' . \Drupal::VERSION . '.' . static::get('deployment_identifier') . '.' . Crypt::hashBase64($root . '/' . $site_path);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.