mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-39117 cachestore_apcu: Update to APCu
We now use APCu as it's support by PHP7 and provides the functionality we need.
This commit is contained in:
parent
cb3e2e144a
commit
58665ecd62
62
cache/stores/apc/README.md
vendored
62
cache/stores/apc/README.md
vendored
@ -1,62 +0,0 @@
|
||||
Alternative PHP cache (APC)
|
||||
===========================
|
||||
|
||||
The alternative PHP cache (APC) is an opcode cache for PHP that provides a persistent application data store cache to PHP applications.
|
||||
This plugin allows the use of the APC data store as a Moodle cache store. In turn allowing you to use APC within Moodle.
|
||||
Its also important to note that because the APCu API is backwards compatible this store can also be used for APCu.
|
||||
|
||||
Installation of APC
|
||||
-------------------
|
||||
|
||||
It is recommended that you read through the APC documentation http://www.php.net/manual/en/book.apc.php before beginning with this plugin.
|
||||
The above documentation recommends installing the PECL APC extension that can be found at http://pecl.php.net/package/apc.
|
||||
http://www.php.net/manual/en/install.pecl.php contains information on installing PECL extensions.
|
||||
|
||||
Its also worth noting for this those using Linux that there is usually a php5-apc package that can be installed very easily.
|
||||
If you have installed PHP under Linux through a package manager then this will be by far the easiest way to proceed.
|
||||
|
||||
Once installed ensure you restart your web server before proceeding.
|
||||
|
||||
Installation within Moodle
|
||||
--------------------------
|
||||
|
||||
Browse to your site and log in as an administrator.
|
||||
Moodle should detect that a new plugin has been added and will proceed to prompt you through an upgrade process to install it.
|
||||
The installation of this plugin is very minimal. Once installed you will need to need to create an APC cache store instance within the Moodle administration interfaces.
|
||||
|
||||
Making use of APC within Moodle
|
||||
-------------------------------
|
||||
|
||||
Installing this plugin makes APC available to use within Moodle however it does not put it into use.
|
||||
The first thing you will need to do is create an APC cache store instance.
|
||||
This is done through the Cache configuration interface.
|
||||
|
||||
1. Log in as an Administrator.
|
||||
2. In the settings block browse to Site Administration > Plugins > Caching > Configuration.
|
||||
3. Once the page loads locate the APC row within the Installed cache stores table.
|
||||
4. You should see an "Add instance" link within that row. If not then the APC extension has not being installed correctly.
|
||||
5. Click "Add instance".
|
||||
6. Give the new instance a name and click "Save changes". You should be directed back to the configuration page.
|
||||
7. Locate the Configured cache store instances table and ensure there is now a row for you APC instance and that it has a green tick in the ready column.
|
||||
|
||||
Once done you have an APC instance that is ready to be used. The next step is to map definitions to make use of the APC instance.
|
||||
|
||||
Locate the known cache definitions table. This table lists the caches being used within Moodle at the moment.
|
||||
For each cache you should be able to Edit mappings. Find a cache that you would like to map to the APC instance and click Edit mappings.
|
||||
One the next screen proceed to select your APC instance as the primary cache and save changes.
|
||||
Back in the known cache definitions table you should now see your APC instance listed under the store mappings for the cache you had selected.
|
||||
You can proceed to map as many or as few cache definitions to the APC instance as you see fit.
|
||||
|
||||
That is it! you are now using APC within Moodle.
|
||||
|
||||
Information and advice on using APC within Moodle
|
||||
-------------------------------------------------
|
||||
|
||||
APC provides a shared application cache that is usually very limited in size but provides excellent performance.
|
||||
It doesn't provide the ability to configure multiple instances of itself and as such within Moodle you are only able to create a single APC cache store instance.
|
||||
Because of its incredible performance but very limited size it is strongly suggested that you map only small, crucial caches to the APC store.
|
||||
|
||||
Another important thing to understand about the APC store is that it provides no garbage cleaning, or storage reclamation facilities. As such cache data will persist there until APC is restarted or the store is purged.
|
||||
On top of that once the store is full requests to store information within the cache fail until there is once more sufficient space.
|
||||
Because of this it is recommended that you regularly purge or restart APC.
|
||||
Also recommended is to map a secondary application cache instance to any definition with the APC mapped. This ensures that if it does indeed full up that an alternative cache is available.
|
@ -14,39 +14,39 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* The library file for the apc cache store.
|
||||
* The library file for the apcu cache store.
|
||||
*
|
||||
* This file is part of the apc cache store, it contains the API for interacting with an instance of the store.
|
||||
* This file is part of the apcu cache store, it contains the API for interacting with an instance of the store.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot.'/cache/forms.php');
|
||||
/**
|
||||
* Form for adding a apc instance.
|
||||
* Form for adding a apcu instance.
|
||||
*
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cachestore_apc_addinstance_form extends cachestore_addinstance_form {
|
||||
class cachestore_apcu_addinstance_form extends cachestore_addinstance_form {
|
||||
/**
|
||||
* Add the desired form elements.
|
||||
*/
|
||||
protected function configuration_definition() {
|
||||
global $CFG;
|
||||
$form = $this->_form;
|
||||
$form->addElement('text', 'prefix', get_string('prefix', 'cachestore_apc'),
|
||||
$form->addElement('text', 'prefix', get_string('prefix', 'cachestore_apcu'),
|
||||
array('maxlength' => 5, 'size' => 5));
|
||||
$form->addHelpButton('prefix', 'prefix', 'cachestore_apc');
|
||||
$form->addHelpButton('prefix', 'prefix', 'cachestore_apcu');
|
||||
$form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext.
|
||||
$form->setDefault('prefix', $CFG->prefix);
|
||||
$form->addRule('prefix', get_string('prefixinvalid', 'cachestore_apc'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
|
||||
$form->addElement('header', 'apc_notice', get_string('notice', 'cachestore_apc'));
|
||||
$form->addRule('prefix', get_string('prefixinvalid', 'cachestore_apcu'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
|
||||
$form->addElement('header', 'apc_notice', get_string('notice', 'cachestore_apcu'));
|
||||
$form->setExpanded('apc_notice');
|
||||
$link = get_docs_url('Caching#APC');
|
||||
$form->addElement('html', nl2br(get_string('clusternotice', 'cachestore_apc', $link)));
|
||||
$form->addElement('html', nl2br(get_string('clusternotice', 'cachestore_apcu', $link)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,16 +65,16 @@ class cachestore_apc_addinstance_form extends cachestore_addinstance_form {
|
||||
$factory = cache_factory::instance();
|
||||
$config = $factory->create_config_instance();
|
||||
foreach ($config->get_all_stores() as $store) {
|
||||
if ($store['plugin'] === 'apc') {
|
||||
if ($store['plugin'] === 'apcu') {
|
||||
if (isset($store['configuration']['prefix'])) {
|
||||
if ($data['prefix'] === $store['configuration']['prefix']) {
|
||||
// The new store has the same prefix as an existing store, thats a problem.
|
||||
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apc');
|
||||
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
|
||||
break;
|
||||
}
|
||||
} else if (empty($data['prefix'])) {
|
||||
// The existing store hasn't got a prefix and neither does the new store, that's a problem.
|
||||
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apc');
|
||||
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -82,4 +82,4 @@ class cachestore_apc_addinstance_form extends cachestore_addinstance_form {
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,21 +15,20 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* APC cache store language strings.
|
||||
* APCu cache store language strings.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['clusternotice'] = 'Please be aware that APC is not a suitable choice on sites running clustered web servers. Use of it in such a setup is highly likely to lead to cached content ending up out of sync with other nodes in the cluster, unless very carefully managed.
|
||||
We recommend you only make use of APC in situations where a single web server is being used.
|
||||
$string['clusternotice'] = 'Please be aware that APCu only a suitable choice for single node sites or caches that can be stored locally.
|
||||
For more information see <a href="{$a}">Moodle docs</a>';
|
||||
$string['notice'] = 'Notice';
|
||||
$string['pluginname'] = 'Alternative PHP cache (APC)';
|
||||
$string['pluginname'] = 'APC User Cache (APCu)';
|
||||
$string['prefix'] = 'Prefix';
|
||||
$string['prefix_help'] = 'The above prefix gets used for all keys being stored in this APC store instance. By default the database prefix is used.';
|
||||
$string['prefixinvalid'] = 'The prefix you have selected is invalid. You can only use a-z A-Z 0-9-_.';
|
||||
$string['prefixnotunique'] = 'The prefix you have selected is not unique. Please choose a unique prefix.';
|
||||
$string['testperformance'] = 'Test performance';
|
||||
$string['testperformance_desc'] = 'If enabled APC performance will be included when viewing the Test performance page in the administration block. Enabling this on a production site is not recommended.';
|
||||
$string['testperformance_desc'] = 'If enabled APCu performance will be included when viewing the Test performance page in the administration block. Enabling this on a production site is not recommended.';
|
126
cache/stores/apc/lib.php → cache/stores/apcu/lib.php
vendored
126
cache/stores/apc/lib.php → cache/stores/apcu/lib.php
vendored
@ -15,25 +15,27 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* APC cache store main library.
|
||||
* APCu cache store main library.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The APC cache store class.
|
||||
* The APCu cache store class.
|
||||
*
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is_configurable {
|
||||
class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_is_configurable {
|
||||
|
||||
/**
|
||||
* The required version of APC for this extension.
|
||||
* The required version of APCu for this extension.
|
||||
*/
|
||||
const REQUIRED_VERSION = '3.1.1';
|
||||
const REQUIRED_VERSION = '4.0.0';
|
||||
|
||||
/**
|
||||
* The name of this store instance.
|
||||
@ -48,26 +50,30 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
protected $definition = null;
|
||||
|
||||
/**
|
||||
* The prefix to use on all keys.
|
||||
* @var null
|
||||
* The storeprefix to use on all instances of this store. Configured as part store setup.
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = null;
|
||||
protected $storeprefix = null;
|
||||
|
||||
/**
|
||||
* Static method to check that the APC stores requirements have been met.
|
||||
* The prefix added specifically for this cache.
|
||||
* @var string
|
||||
*/
|
||||
protected $cacheprefix = null;
|
||||
|
||||
/**
|
||||
* Static method to check that the APCu stores requirements have been met.
|
||||
*
|
||||
* It checks that the APC extension has been loaded and that it has been enabled.
|
||||
* It checks that the APCu extension has been loaded and that it has been enabled.
|
||||
*
|
||||
* @return bool True if the stores software/hardware requirements have been met and it can be used. False otherwise.
|
||||
*/
|
||||
public static function are_requirements_met() {
|
||||
if (!extension_loaded('apc') || // APC PHP extension is not available.
|
||||
!ini_get('apc.enabled') // APC is not enabled.
|
||||
) {
|
||||
if (!extension_loaded('apcu') || !ini_get('apc.enabled')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$version = phpversion('apc');
|
||||
$version = phpversion('apcu');
|
||||
return $version && version_compare($version, self::REQUIRED_VERSION, '>=');
|
||||
}
|
||||
|
||||
@ -88,7 +94,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return int The supported features.
|
||||
*/
|
||||
public static function get_supported_features(array $configuration = array()) {
|
||||
return self::SUPPORTS_DATA_GUARANTEE + self::SUPPORTS_NATIVE_TTL;
|
||||
return self::SUPPORTS_NATIVE_TTL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,9 +118,9 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
public function __construct($name, array $configuration = array()) {
|
||||
global $CFG;
|
||||
$this->name = $name;
|
||||
$this->prefix = $CFG->prefix;
|
||||
$this->storeprefix = $CFG->prefix;
|
||||
if (isset($configuration['prefix'])) {
|
||||
$this->prefix = $configuration['prefix'];
|
||||
$this->storeprefix = $configuration['prefix'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +142,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
*/
|
||||
public function initialise(cache_definition $definition) {
|
||||
$this->definition = $definition;
|
||||
$this->prefix = $definition->generate_definition_hash().'__';
|
||||
$this->cacheprefix = $this->storeprefix.$definition->generate_definition_hash().'__';
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -162,10 +168,12 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
*
|
||||
* Should be called before all interaction.
|
||||
*
|
||||
* @param string $key The key to prepare for storing in APCu.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function prepare_key($key) {
|
||||
return $this->prefix . $key;
|
||||
return $this->cacheprefix . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,7 +185,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
public function get($key) {
|
||||
$key = $this->prepare_key($key);
|
||||
$success = false;
|
||||
$outcome = apc_fetch($key, $success);
|
||||
$outcome = apcu_fetch($key, $success);
|
||||
if ($success) {
|
||||
return $outcome;
|
||||
}
|
||||
@ -200,13 +208,17 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
}
|
||||
$outcomes = array();
|
||||
$success = false;
|
||||
$results = apc_fetch($map, $success);
|
||||
foreach ($map as $key => $used) {
|
||||
if ($success && array_key_exists($used, $results) && !empty($results[$used])) {
|
||||
$outcomes[$key] = $results[$used];
|
||||
} else {
|
||||
$outcomes[$key] = false;
|
||||
$results = apcu_fetch($map, $success);
|
||||
if ($success) {
|
||||
foreach ($map as $key => $used) {
|
||||
if (array_key_exists($used, $results)) {
|
||||
$outcomes[$key] = $results[$used];
|
||||
} else {
|
||||
$outcomes[$key] = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$outcomes = array_fill_keys($keys, false);
|
||||
}
|
||||
return $outcomes;
|
||||
}
|
||||
@ -220,7 +232,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
*/
|
||||
public function set($key, $data) {
|
||||
$key = $this->prepare_key($key);
|
||||
return apc_store($key, $data, $this->definition->get_ttl());
|
||||
return apcu_store($key, $data, $this->definition->get_ttl());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +249,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
$key = $this->prepare_key($pair['key']);
|
||||
$map[$key] = $pair['value'];
|
||||
}
|
||||
$result = apc_store($map, null, $this->definition->get_ttl());
|
||||
$result = apcu_store($map, null, $this->definition->get_ttl());
|
||||
return count($map) - count($result);
|
||||
}
|
||||
|
||||
@ -249,7 +261,7 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
*/
|
||||
public function delete($key) {
|
||||
$key = $this->prepare_key($key);
|
||||
return apc_delete($key);
|
||||
return apcu_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,15 +286,24 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return boolean True on success. False otherwise.
|
||||
*/
|
||||
public function purge() {
|
||||
$iterator = new APCIterator('user', '#^' . preg_quote($this->prefix, '#') . '#');
|
||||
return apc_delete($iterator);
|
||||
if (class_exists('APCUIterator', false)) {
|
||||
$iterator = new APCUIterator('#^' . preg_quote($this->cacheprefix, '#') . '#');
|
||||
} else {
|
||||
$iterator = new APCIterator('user', '#^' . preg_quote($this->cacheprefix, '#') . '#');
|
||||
}
|
||||
return apcu_delete($iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs any necessary clean up when the store instance is being deleted.
|
||||
*/
|
||||
public function cleanup() {
|
||||
$this->purge();
|
||||
public function instance_deleted() {
|
||||
if (class_exists('APCUIterator', false)) {
|
||||
$iterator = new APCUIterator('#^' . preg_quote($this->storeprefix, '#') . '#');
|
||||
} else {
|
||||
$iterator = new APCIterator('user', '#^' . preg_quote($this->storeprefix, '#') . '#');
|
||||
}
|
||||
return apcu_delete($iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,15 +315,15 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return cache_store
|
||||
*/
|
||||
public static function initialise_test_instance(cache_definition $definition) {
|
||||
$testperformance = get_config('cachestore_apc', 'testperformance');
|
||||
$testperformance = get_config('cachestore_apcu', 'testperformance');
|
||||
if (empty($testperformance)) {
|
||||
return false;
|
||||
}
|
||||
if (!self::are_requirements_met()) {
|
||||
return false;
|
||||
}
|
||||
$name = 'APC test';
|
||||
$cache = new cachestore_apc($name);
|
||||
$name = 'APCu test';
|
||||
$cache = new cachestore_apcu($name);
|
||||
$cache->initialise($definition);
|
||||
return $cache;
|
||||
}
|
||||
@ -314,7 +335,8 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return bool True if the cache has the requested key, false otherwise.
|
||||
*/
|
||||
public function has($key) {
|
||||
return apc_exists($key);
|
||||
$key = $this->prepare_key($key);
|
||||
return apcu_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,7 +346,10 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return bool True if the cache has at least one of the given keys
|
||||
*/
|
||||
public function has_any(array $keys) {
|
||||
$result = apc_exists($keys);
|
||||
foreach ($keys as $arraykey => $key) {
|
||||
$keys[$arraykey] = $this->prepare_key($key);
|
||||
}
|
||||
$result = apcu_exists($keys);
|
||||
return count($result) > 0;
|
||||
}
|
||||
|
||||
@ -335,7 +360,10 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return bool True if the cache has all of the given keys, false otherwise.
|
||||
*/
|
||||
public function has_all(array $keys) {
|
||||
$result = apc_exists($keys);
|
||||
foreach ($keys as $arraykey => $key) {
|
||||
$keys[$arraykey] = $this->prepare_key($key);
|
||||
}
|
||||
$result = apcu_exists($keys);
|
||||
return count($result) === count($keys);
|
||||
}
|
||||
|
||||
@ -343,17 +371,14 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* Generates an instance of the cache store that can be used for testing.
|
||||
*
|
||||
* @param cache_definition $definition
|
||||
* @return cachestore_apc|false
|
||||
* @return cachestore_apcu|false
|
||||
*/
|
||||
public static function initialise_unit_test_instance(cache_definition $definition) {
|
||||
if (!self::are_requirements_met()) {
|
||||
return false;
|
||||
}
|
||||
if (!defined('TEST_CACHESTORE_APC')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$store = new cachestore_apc('Test APC', array('prefix' => 'phpunit'));
|
||||
$store = new cachestore_apcu('Test APCu', array('prefix' => 'phpunit'));
|
||||
if (!$store->is_ready()) {
|
||||
return false;
|
||||
}
|
||||
@ -369,9 +394,12 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
* @return array
|
||||
*/
|
||||
public static function config_get_configuration_array($data) {
|
||||
return array(
|
||||
'prefix' => $data->prefix,
|
||||
);
|
||||
$config = array();
|
||||
|
||||
if (isset($data->prefix)) {
|
||||
$config['prefix'] = $data->prefix;
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
/**
|
||||
* Allows the cache store to set its data against the edit form before it is shown to the user.
|
||||
@ -387,4 +415,4 @@ class cachestore_apc extends cache_store implements cache_is_key_aware, cache_is
|
||||
}
|
||||
$editform->set_data($data);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,11 +15,11 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The settings for the APC store.
|
||||
* The settings for the APCu store.
|
||||
*
|
||||
* This file is part of the APC cache store, it contains the API for interacting with an instance of the store.
|
||||
* This file is part of the APCu cache store, it contains the API for interacting with an instance of the store.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -28,9 +28,9 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$settings->add(
|
||||
new admin_setting_configcheckbox(
|
||||
'cachestore_apc/testperformance',
|
||||
new lang_string('testperformance', 'cachestore_apc'),
|
||||
new lang_string('testperformance_desc', 'cachestore_apc'),
|
||||
'cachestore_apcu/testperformance',
|
||||
new lang_string('testperformance', 'cachestore_apcu'),
|
||||
new lang_string('testperformance_desc', 'cachestore_apcu'),
|
||||
false
|
||||
)
|
||||
);
|
@ -15,14 +15,9 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* APC unit tests.
|
||||
* APCu unit tests.
|
||||
*
|
||||
* If you wish to use these unit tests all you need to do is add the following definition to
|
||||
* your config.php file.
|
||||
*
|
||||
* define('TEST_CACHESTORE_XCACHE', true);
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -32,67 +27,61 @@ defined('MOODLE_INTERNAL') || die();
|
||||
// Include the necessary evils.
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/cache/tests/fixtures/stores.php');
|
||||
require_once($CFG->dirroot.'/cache/stores/apc/lib.php');
|
||||
require_once($CFG->dirroot.'/cache/stores/apcu/lib.php');
|
||||
|
||||
/**
|
||||
* APC unit test class.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2014 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class cachestore_apc_test extends cachestore_tests {
|
||||
class cachestore_apcu_test extends cachestore_tests {
|
||||
/**
|
||||
* Returns the apc class name
|
||||
* Returns the apcu class name
|
||||
* @return string
|
||||
*/
|
||||
protected function get_class_name() {
|
||||
return 'cachestore_apc';
|
||||
return 'cachestore_apcu';
|
||||
}
|
||||
|
||||
/**
|
||||
* Test purging the apc cache store.
|
||||
*/
|
||||
public function test_purge() {
|
||||
if (!cachestore_apc::are_requirements_met() || !defined('TEST_CACHESTORE_APC')) {
|
||||
$this->markTestSkipped('Could not test cachestore_apc. Requirements are not met.');
|
||||
public function setUp() {
|
||||
if (!cachestore_apcu::are_requirements_met()) {
|
||||
$this->markTestSkipped('Could not test cachestore_apcu. Requirements are not met.');
|
||||
}
|
||||
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apc', 'phpunit_test');
|
||||
$instance = cachestore_apc::initialise_unit_test_instance($definition);
|
||||
|
||||
// Test a simple purge return.
|
||||
$this->assertTrue($instance->purge());
|
||||
|
||||
// Test purge works.
|
||||
$this->assertTrue($instance->set('test', 'monster'));
|
||||
$this->assertSame('monster', $instance->get('test'));
|
||||
$this->assertTrue($instance->purge());
|
||||
$this->assertFalse($instance->get('test'));
|
||||
return parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the Moodle APC store doesn't cross paths with other code using APC as well.
|
||||
* Test that the Moodle APCu store doesn't cross paths with other code using APCu as well.
|
||||
*/
|
||||
public function test_cross_application_interaction() {
|
||||
if (!cachestore_apc::are_requirements_met() || !defined('TEST_CACHESTORE_APC')) {
|
||||
$this->markTestSkipped('Could not test cachestore_apc. Requirements are not met.');
|
||||
}
|
||||
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apc', 'phpunit_test');
|
||||
$instance = cachestore_apc::initialise_unit_test_instance($definition);
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
|
||||
$instance = cachestore_apcu::initialise_unit_test_instance($definition);
|
||||
|
||||
// Test purge with custom data.
|
||||
$this->assertTrue($instance->set('test', 'monster'));
|
||||
$this->assertSame('monster', $instance->get('test'));
|
||||
$this->assertTrue(apc_store('test', 'pirate', 180));
|
||||
$this->assertTrue(apcu_store('test', 'pirate', 180));
|
||||
$this->assertSame('monster', $instance->get('test'));
|
||||
$this->assertTrue(apc_exists('test'));
|
||||
$this->assertSame('pirate', apc_fetch('test'));
|
||||
$this->assertTrue(apcu_exists('test'));
|
||||
$this->assertSame('pirate', apcu_fetch('test'));
|
||||
// Purge and check that our data is gone but the the custom data is still there.
|
||||
$this->assertTrue($instance->purge());
|
||||
$this->assertFalse($instance->get('test'));
|
||||
$this->assertTrue(apc_exists('test'));
|
||||
$this->assertSame('pirate', apc_fetch('test'));
|
||||
$this->assertTrue(apcu_exists('test'));
|
||||
$this->assertSame('pirate', apcu_fetch('test'));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_different_caches_have_different_prefixes() {
|
||||
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
|
||||
$instance = cachestore_apcu::initialise_unit_test_instance($definition);
|
||||
$definition2 = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test2');
|
||||
$instance2 = cachestore_apcu::initialise_unit_test_instance($definition2);
|
||||
|
||||
$instance->set('test1', 1);
|
||||
$this->assertFalse($instance2->get('test1'));
|
||||
$instance2->purge();
|
||||
$this->assertSame(1, $instance->get('test1'));
|
||||
}
|
||||
}
|
@ -15,16 +15,16 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* APC cache store version information.
|
||||
* APCu cache store version information.
|
||||
*
|
||||
* @package cachestore_apc
|
||||
* @package cachestore_apcu
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$plugin->version = 2014111400;
|
||||
$plugin->requires = 2014111300;
|
||||
$plugin->version = 2016081600;
|
||||
$plugin->requires = 2016081100;
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->component = 'cachestore_apc';
|
||||
$plugin->component = 'cachestore_apcu';
|
@ -1744,7 +1744,7 @@ class core_plugin_manager {
|
||||
),
|
||||
|
||||
'cachestore' => array(
|
||||
'file', 'memcache', 'memcached', 'mongodb', 'session', 'static'
|
||||
'file', 'memcache', 'memcached', 'mongodb', 'session', 'static', 'apcu'
|
||||
),
|
||||
|
||||
'calendartype' => array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user