Commit dfe09269 authored by alexpott's avatar alexpott

Issue #2617568 by amateescu, cilefen, Fabianx: Rename apc_* functions with apcu_*

parent ba82fc6c
......@@ -567,7 +567,7 @@
*
* By default cached data is stored in the database. This can be configured
* though so that all cached data, or that of an individual cache bin, uses a
* different cache backend, such as APC or Memcache, for storage.
* different cache backend, such as APCu or Memcache, for storage.
*
* In a settings.php file, you can override the service used for a particular
* cache bin. For example, if your service implementation of
......
......@@ -16,21 +16,21 @@ class ApcuFileCacheBackend implements FileCacheBackendInterface {
* {@inheritdoc}
*/
public function fetch(array $cids) {
return apc_fetch($cids);
return apcu_fetch($cids);
}
/**
* {@inheritdoc}
*/
public function store($cid, $data) {
apc_store($cid, $data);
apcu_store($cid, $data);
}
/**
* {@inheritdoc}
*/
public function delete($cid) {
apc_delete($cid);
apcu_delete($cid);
}
}
......@@ -30,16 +30,6 @@ public static function invalidate($pathname) {
if (function_exists('opcache_invalidate')) {
opcache_invalidate($pathname, TRUE);
}
// If apcu extension is enabled in PHP 5.5 or greater it emulates apc.
// This is to provide an easy upgrade path if you are using apc's user
// caching however the emulation does not extend to opcode caching.
// Therefore we need to check if the function exists as well.
if (extension_loaded('apc') && function_exists('apc_delete_file')) {
// apc_delete_file() throws a PHP warning in case the specified file was
// not compiled yet.
// @see http://php.net/manual/en/function.apc-delete-file.php
@apc_delete_file($pathname);
}
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Cache\Apcu4Backend.
*/
namespace Drupal\Core\Cache;
/**
* Stores cache items in the Alternative PHP Cache User Cache (APCu).
*
* This class is used with APCu versions >= 4.0.0 and < 5.0.0.
*/
class Apcu4Backend extends ApcuBackend {
/**
* {@inheritdoc}
*
* @return \APCIterator
*/
protected function getIterator($search = NULL, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) {
return new \APCIterator('user', $search, $format, $chunk_size, $list);
}
}
......@@ -60,7 +60,7 @@ public function __construct($bin, $site_prefix, CacheTagsChecksumInterface $chec
}
/**
* Prepends the APC user variable prefix for this bin to a cache item ID.
* Prepends the APCu user variable prefix for this bin to a cache item ID.
*
* @param string $cid
* The cache item ID to prefix.
......@@ -76,7 +76,7 @@ public function getApcuKey($cid) {
* {@inheritdoc}
*/
public function get($cid, $allow_invalid = FALSE) {
$cache = apc_fetch($this->getApcuKey($cid));
$cache = apcu_fetch($this->getApcuKey($cid));
return $this->prepareItem($cache, $allow_invalid);
}
......@@ -90,7 +90,7 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
$map[$this->getApcuKey($cid)] = $cid;
}
$result = apc_fetch(array_keys($map));
$result = apcu_fetch(array_keys($map));
$cache = array();
if ($result) {
foreach ($result as $key => $item) {
......@@ -112,18 +112,18 @@ public function getMultiple(&$cids, $allow_invalid = FALSE) {
* APCu is a memory cache, shared across all server processes. To prevent
* cache item clashes with other applications/installations, every cache item
* is prefixed with a unique string for this site. Therefore, functions like
* apc_clear_cache() cannot be used, and instead, a list of all cache items
* apcu_clear_cache() cannot be used, and instead, a list of all cache items
* belonging to this application need to be retrieved through this method
* instead.
*
* @param string $prefix
* (optional) A cache ID prefix to limit the result to.
*
* @return \APCIterator
* An APCIterator containing matched items.
* @return \APCUIterator
* An APCUIterator containing matched items.
*/
protected function getAll($prefix = '') {
return new \APCIterator('user', '/^' . preg_quote($this->getApcuKey($prefix), '/') . '/');
return $this->getIterator('/^' . preg_quote($this->getApcuKey($prefix), '/') . '/');
}
/**
......@@ -174,12 +174,12 @@ public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANEN
$cache->expire = $expire;
$cache->tags = implode(' ', $tags);
$cache->checksum = $this->checksumProvider->getCurrentChecksum($tags);
// APC serializes/unserializes any structure itself.
// APCu serializes/unserializes any structure itself.
$cache->serialized = 0;
$cache->data = $data;
// Expiration is handled by our own prepareItem(), not APCu.
apc_store($this->getApcuKey($cid), $cache);
apcu_store($this->getApcuKey($cid), $cache);
}
/**
......@@ -195,35 +195,35 @@ public function setMultiple(array $items = array()) {
* {@inheritdoc}
*/
public function delete($cid) {
apc_delete($this->getApcuKey($cid));
apcu_delete($this->getApcuKey($cid));
}
/**
* {@inheritdoc}
*/
public function deleteMultiple(array $cids) {
apc_delete(array_map(array($this, 'getApcuKey'), $cids));
apcu_delete(array_map(array($this, 'getApcuKey'), $cids));
}
/**
* {@inheritdoc}
*/
public function deleteAll() {
apc_delete(new \APCIterator('user', '/^' . preg_quote($this->binPrefix, '/') . '/'));
apcu_delete($this->getIterator('/^' . preg_quote($this->binPrefix, '/') . '/'));
}
/**
* {@inheritdoc}
*/
public function garbageCollection() {
// APC performs garbage collection automatically.
// APCu performs garbage collection automatically.
}
/**
* {@inheritdoc}
*/
public function removeBin() {
apc_delete(new \APCIterator('user', '/^' . preg_quote($this->binPrefix, '/') . '/'));
apcu_delete($this->getIterator('/^' . preg_quote($this->binPrefix, '/') . '/'));
}
/**
......@@ -252,4 +252,25 @@ public function invalidateAll() {
}
}
/**
* Instantiates and returns the APCUIterator class.
*
* @param mixed $search
* A PCRE regular expression that matches against APC key names, either as a
* string for a single regular expression, or as an array of regular
* expressions. Or, optionally pass in NULL to skip the search.
* @param int $format
* The desired format, as configured with one or more of the APC_ITER_*
* constants.
* @param int $chunk_size
* The chunk size. Must be a value greater than 0. The default value is 100.
* @param int $list
* The type to list. Either pass in APC_LIST_ACTIVE or APC_LIST_DELETED.
*
* @return \APCUIterator
*/
protected function getIterator($search = NULL, $format = APC_ITER_ALL, $chunk_size = 100, $list = APC_LIST_ACTIVE) {
return new \APCUIterator($search, $format, $chunk_size, $list);
}
}
......@@ -25,6 +25,13 @@ class ApcuBackendFactory implements CacheFactoryInterface {
*/
protected $checksumProvider;
/**
* The APCU backend class to use.
*
* @var string
*/
protected $backendClass;
/**
* Constructs an ApcuBackendFactory object.
*
......@@ -38,6 +45,12 @@ class ApcuBackendFactory implements CacheFactoryInterface {
public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
$this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
$this->checksumProvider = $checksum_provider;
if (version_compare(phpversion('apcu'), '5.0.0', '>=')) {
$this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
}
else {
$this->backendClass = 'Drupal\Core\Cache\Apcu4Backend';
}
}
/**
......@@ -50,7 +63,7 @@ public function __construct($root, $site_path, CacheTagsChecksumInterface $check
* The cache backend object for the specified cache bin.
*/
public function get($bin) {
return new ApcuBackend($bin, $this->sitePrefix, $this->checksumProvider);
return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);
}
}
......@@ -53,7 +53,7 @@ public function __construct(Settings $settings = NULL, $consistent_service_name
}
// Default the fast backend to APCu if it's available.
if (!isset($fast_service_name) && function_exists('apc_fetch')) {
if (!isset($fast_service_name) && function_exists('apcu_fetch')) {
$fast_service_name = 'cache.backend.apcu';
}
......
......@@ -428,7 +428,7 @@ public function boot() {
];
// @todo Use extension_loaded('apcu') for non-testbot
// https://www.drupal.org/node/2447753.
if (function_exists('apc_fetch')) {
if (function_exists('apcu_fetch')) {
$configuration['default']['cache_backend_class'] = '\Drupal\Component\FileCache\ApcuFileCacheBackend';
}
}
......@@ -968,11 +968,11 @@ protected function initializeSettings(Request $request) {
}
}
// If the class loader is still the same, possibly upgrade to the APC class
// If the class loader is still the same, possibly upgrade to the APCu class
// loader.
if ($class_loader_class == get_class($this->classLoader)
&& Settings::get('class_loader_auto_detect', TRUE)
&& function_exists('apc_fetch')) {
&& function_exists('apcu_fetch')) {
$prefix = Settings::getApcuPrefix('class_loader', $this->root);
$apc_loader = new \Symfony\Component\ClassLoader\ApcClassLoader($prefix, $this->classLoader);
$this->classLoader->unregister();
......
......@@ -149,24 +149,24 @@ public static function getHashSalt() {
}
/**
* Generates a prefix for APC user cache keys.
* Generates a prefix for APCu user cache keys.
*
* A standardized prefix is useful to allow visual inspection of an APC user
* 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 WebTestBase to use the same prefix ensuring that the
* number of APC items created during a full test run is kept to a minimum.
* 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 APC cache items.
* to share APCu cache items.
*
* @param $identifier
* An identifier for the prefix. For example, 'class_loader' or
* 'cache_backend'.
*
* @return string
* The prefix for APC user cache keys.
* The prefix for APCu user cache keys.
*/
public static function getApcuPrefix($identifier, $root, $site_path = '') {
if (static::get('apcu_ensure_unique_prefix', TRUE)) {
......
......@@ -96,16 +96,16 @@ function file_requirements($phase) {
$value = t('Not enabled');
$description = t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php or PHP-FPM and not as FastCGI.');
}
elseif (!$implementation && extension_loaded('apc')) {
elseif (!$implementation && extension_loaded('apcu')) {
$value = t('Not enabled');
$description = t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add <code>apc.rfc1867 = 1</code> to your php.ini configuration. Alternatively, it is recommended to use <a href=":url">PECL uploadprogress</a>, which supports more than one simultaneous upload.', array(':url' => 'http://pecl.php.net/package/uploadprogress'));
}
elseif (!$implementation) {
$value = t('Not enabled');
$description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href=":uploadprogress_url">PECL uploadprogress library</a> (preferred) or to install <a href=":apc_url">APC</a>.', array(':uploadprogress_url' => 'http://pecl.php.net/package/uploadprogress', ':apc_url' => 'http://php.net/apc'));
$description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href=":uploadprogress_url">PECL uploadprogress library</a> (preferred) or to install <a href=":apc_url">APC</a>.', array(':uploadprogress_url' => 'http://pecl.php.net/package/uploadprogress', ':apc_url' => 'http://php.net/apcu'));
}
elseif ($implementation == 'apc') {
$value = t('Enabled (<a href=":url">APC RFC1867</a>)', array(':url' => 'http://php.net/manual/apc.configuration.php#ini.apc.rfc1867'));
$value = t('Enabled (<a href=":url">APC RFC1867</a>)', array(':url' => 'http://php.net/manual/en/apcu.configuration.php#ini.apcu.rfc1867'));
$description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the <a href=":url">PECL uploadprogress library</a> if possible.', array(':url' => 'http://pecl.php.net/package/uploadprogress'));
}
elseif ($implementation == 'uploadprogress') {
......
......@@ -913,7 +913,7 @@ function file_progress_implementation() {
$implementation = FALSE;
// We prefer the PECL extension uploadprogress because it supports multiple
// simultaneous uploads. APC only supports one at a time.
// simultaneous uploads. APCu only supports one at a time.
if (extension_loaded('uploadprogress')) {
$implementation = 'uploadprogress';
}
......
......@@ -38,7 +38,7 @@ public function progress($key) {
}
}
elseif ($implementation == 'apc') {
$status = apc_fetch('upload_' . $key);
$status = apcu_fetch('upload_' . $key);
if (isset($status['current']) && !empty($status['total'])) {
$progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total'])));
$progress['percentage'] = round(100 * $status['current'] / $status['total']);
......
......@@ -7,6 +7,7 @@
namespace Drupal\system\Tests\Cache;
use Drupal\Core\Cache\Apcu4Backend;
use Drupal\Core\Cache\ApcuBackend;
/**
......@@ -21,7 +22,7 @@ class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
* Get a list of failed requirements.
*
* This specifically bypasses checkRequirements because it fails tests. PHP 7
* does not have APC and simpletest does not have a explicit "skip"
* does not have APCu and simpletest does not have a explicit "skip"
* functionality so to emulate it we override all test methods and explicitly
* pass when requirements are not met.
*
......@@ -29,13 +30,10 @@ class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
*/
protected function getRequirements() {
$requirements = [];
if (!extension_loaded('apc')) {
$requirements[] = 'APC extension not found.';
if (!extension_loaded('apcu')) {
$requirements[] = 'APCu 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.';
}
......@@ -66,7 +64,12 @@ protected function requirementsFail() {
* {@inheritdoc}
*/
protected function createCacheBackend($bin) {
return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
if (version_compare(phpversion('apcu'), '5.0.0', '>=')) {
return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
}
else {
return new Apcu4Backend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
}
}
/**
......@@ -91,7 +94,15 @@ public function testSetGet() {
// Make sure entries are permanent (i.e. no TTL).
$backend = $this->getCacheBackend($this->getTestBin());
$key = $backend->getApcuKey('TEST8');
foreach (new \APCIterator('user', '/^' . $key . '/') as $item) {
if (class_exists('\APCUIterator')) {
$iterator = new \APCUIterator('/^' . $key . '/');
}
else {
$iterator = new \APCIterator('user', '/^' . $key . '/');
}
foreach ($iterator as $item) {
$this->assertEqual(0, $item['ttl']);
$found = TRUE;
}
......
......@@ -42,10 +42,7 @@
((REQUEST_TIME - $request->get('timestamp')) < 300) &&
Crypt::hashEquals(Crypt::hmacBase64($request->get('timestamp'), Settings::get('hash_salt')), $request->get('token'))
)) {
// Clear the APC cache to ensure APC class loader is reset.
if (function_exists('apc_clear_cache')) {
apc_clear_cache('user');
}
// Clear the APCu cache to ensure APCu class loader is reset.
if (function_exists('apcu_clear_cache')) {
apcu_clear_cache();
}
......
......@@ -509,7 +509,7 @@ protected function initFileCache() {
];
// @todo Use extension_loaded('apcu') for non-testbot
// https://www.drupal.org/node/2447753.
if (function_exists('apc_fetch')) {
if (function_exists('apcu_fetch')) {
$configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class;
}
}
......
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