Commit 50cd0871 authored by Dries's avatar Dries

Issue #1807662 by sun, beejeebus, damiankloip, Wim Leers, Mixologic: Built-in...

Issue #1807662 by sun, beejeebus, damiankloip, Wim Leers, Mixologic: Built-in APCu support in core (PHP 5.5 only).
parent c98b2fdc
......@@ -25,6 +25,8 @@ services:
cache.backend.database:
class: Drupal\Core\Cache\DatabaseBackendFactory
arguments: ['@database']
cache.backend.apcu:
class: Drupal\Core\Cache\ApcuBackendFactory
cache.backend.php:
class: Drupal\Core\Cache\PhpBackendFactory
cache.backend.memory:
......
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\Core\Cache\ApcuBackendFactory.
*/
namespace Drupal\Core\Cache;
use \Drupal\Component\Utility\Crypt;
class ApcuBackendFactory implements CacheFactoryInterface {
/**
* The site prefix string.
*
* @var string
*/
protected $sitePrefix;
/**
* Constructs an ApcuBackendFactory object.
*/
public function __construct() {
$this->sitePrefix = Crypt::hashBase64(DRUPAL_ROOT . '/' . conf_path());
}
/**
* 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.
*/
public function get($bin) {
return new ApcuBackend($bin, $this->sitePrefix);
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Cache\ApcuBackendUnitTest.
*/
namespace Drupal\system\Tests\Cache;
use Drupal\Core\Cache\ApcuBackend;
/**
* Tests the APCu cache backend.
*/
class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
public static function getInfo() {
return array(
'name' => 'APCu cache backend',
'description' => 'Tests the APCu cache backend.',
'group' => 'Cache',
);
}
protected function checkRequirements() {
$requirements = parent::checkRequirements();
if (!extension_loaded('apc')) {
$requirements[] = 'APC extension not found.';
}
else {
if (version_compare(phpversion('apc'), '3.1.1', '<')) {
$requirements[] = 'APC extension must be newer than 3.1.1 for APCIterator support.';
}
if (PHP_SAPI === 'cli' && !ini_get('apc.enable_cli')) {
$requirements[] = 'apc.enable_cli must be enabled to run this test.';
}
}
return $requirements;
}
protected function createCacheBackend($bin) {
$this->backend = new ApcuBackend($bin, $this->databasePrefix);
return $this->backend;
}
public function tearDown() {
$this->backend->removeBin();
parent::tearDown();
$this->backend = NULL;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment