getApcuPrefix example

/** * Tests Settings::getApcuPrefix(). * * @covers ::getApcuPrefix */
  public function testGetApcuPrefix() {
    $settings = new Settings([
      'hash_salt' => 123,
      'apcu_ensure_unique_prefix' => TRUE,
    ]);
    $this->assertNotEquals($settings::getApcuPrefix('cache_test', '/test/a')$settings::getApcuPrefix('cache_test', '/test/b'));

    $settings = new Settings([
      'hash_salt' => 123,
      'apcu_ensure_unique_prefix' => FALSE,
    ]);
    $this->assertNotEquals($settings::getApcuPrefix('cache_test', '/test/a')$settings::getApcuPrefix('cache_test', '/test/b'));
  }

  /** * Tests that an exception is thrown when settings are not initialized yet. * * @covers ::getInstance */
$configuration = Settings::get('file_cache');

    // Provide a default configuration, if not set.     if (!isset($configuration['default'])) {
      // @todo Use extension_loaded('apcu') for non-testbot       // https://www.drupal.org/node/2447753.       if (function_exists('apcu_fetch')) {
        $configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class;
      }
    }
    FileCacheFactory::setConfiguration($configuration);
    FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
  }

  /** * Returns Extension objects for $modules to enable. * * @param string[] $modules * The list of modules to enable. * * @return \Drupal\Core\Extension\Extension[] * Extension objects for $modules, keyed by module name. * * @throws \PHPUnit\Framework\Exception * If a module is not available. * * @see \Drupal\Tests\KernelTestBase::enableModules() * @see \Drupal\Core\Extension\ModuleHandler::add() */
/** * Constructs an ApcuBackendFactory object. * * @param string $root * The app root. * @param string $site_path * The site path. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. */
  public function __construct($root$site_path, CacheTagsChecksumInterface $checksum_provider) {
    $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root$site_path);
    $this->checksumProvider = $checksum_provider;
    $this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
  }

  /** * Gets ApcuBackend for the specified cache bin. * * @param $bin * The cache bin for which the object is created. * * @return \Drupal\Core\Cache\ApcuBackend * The cache backend object for the specified cache bin. */
    $configuration = Settings::get('file_cache');

    // Provide a default configuration, if not set.     if (!isset($configuration['default'])) {
      // @todo Use extension_loaded('apcu') for non-testbot       // https://www.drupal.org/node/2447753.       if (function_exists('apcu_fetch')) {
        $configuration['default']['cache_backend_class'] = '\Drupal\Component\FileCache\ApcuFileCacheBackend';
      }
    }
    FileCacheFactory::setConfiguration($configuration);
    FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));

    $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition));

    // Initialize the container.     $this->initializeContainer();

    // Add the APCu prefix to use to cache found/not-found classes.     if (Settings::get('class_loader_auto_detect', TRUE) && method_exists($this->classLoader, 'setApcuPrefix')) {
      // Vary the APCu key by which modules are installed to allow       // class_exists() checks to determine functionality.       $id = 'class_loader:' . crc32(implode(':', array_keys($this->container->getParameter('container.modules'))));
      
Home | Imprint | This part of the site doesn't use cookies.