Skip to content

Commit

Permalink
MDL-82158 core_cache: Coding style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Aug 20, 2024
1 parent bac9672 commit b92008c
Show file tree
Hide file tree
Showing 53 changed files with 2,510 additions and 2,085 deletions.
8 changes: 4 additions & 4 deletions cache/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
*
* This file is part of Moodle's cache API, affectionately called MUC.
*
* @package core
* @package core_cache
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../config.php');
require_once($CFG->dirroot.'/lib/adminlib.php');
require_once($CFG->dirroot . '/lib/adminlib.php');

// The first time the user visits this page we are going to reparse the definitions.
// Just ensures that everything is up to date.
Expand All @@ -42,7 +42,7 @@
admin_externalpage_setup('cacheconfig');
$adminhelper = cache_factory::instance()->get_administration_display_helper();

$notifications = array();
$notifications = [];
// Empty array to hold any form information returned from actions.
$forminfo = [];

Expand All @@ -57,7 +57,7 @@
// Add cache store warnings to the list of notifications.
// Obviously as these are warnings they are show as failures.
foreach (cache_helper::warnings(core_cache\administration_helper::get_store_instance_summaries()) as $warning) {
$notifications[] = array($warning, false);
$notifications[] = [$warning, false];
}

// Decide on display mode based on returned forminfo.
Expand Down
184 changes: 85 additions & 99 deletions cache/classes/administration_helper.php

Large diffs are not rendered by default.

54 changes: 37 additions & 17 deletions cache/classes/application_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace core_cache;

use core\exception\coding_exception;
use core\exception\moodle_exception;

/**
* An application cache.
*
Expand All @@ -26,13 +31,12 @@
*
* @internal don't use me directly.
*
* @package core
* @package core_cache
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cache_application extends cache implements cache_loader_with_locking {

class application_cache extends cache implements loader_with_locking_interface {
/**
* Lock identifier.
* This is used to ensure the lock belongs to the cache instance + definition + user.
Expand All @@ -43,7 +47,7 @@ class cache_application extends cache implements cache_loader_with_locking {
/**
* Gets set to true if the cache's primary store natively supports locking.
* If it does then we use that, otherwise we need to instantiate a second store to use for locking.
* @var cache_store
* @var store
*/
protected $nativelocking = null;

Expand All @@ -62,7 +66,7 @@ class cache_application extends cache implements cache_loader_with_locking {
protected $requirelockingbeforewrite = false;

/**
* Gets set to a cache_store to use for locking if the caches primary store doesn't support locking natively.
* Gets set to a store to use for locking if the caches primary store doesn't support locking natively.
* @var cache_lock_interface
*/
protected $cachelockinstance;
Expand All @@ -78,11 +82,11 @@ class cache_application extends cache implements cache_loader_with_locking {
*
* You should not call this method from your code, instead you should use the cache::make methods.
*
* @param cache_definition $definition
* @param cache_store $store
* @param cache_loader|cache_data_source $loader
* @param definition $definition
* @param store $store
* @param loader_interface|data_source_interface $loader
*/
public function __construct(cache_definition $definition, cache_store $store, $loader = null) {
public function __construct(definition $definition, store $store, $loader = null) {
parent::__construct($definition, $store, $loader);
$this->nativelocking = $this->store_supports_native_locking();
if ($definition->require_locking()) {
Expand Down Expand Up @@ -141,7 +145,7 @@ public function acquire_lock($key) {
// We need to release this lock later if the lock is not successful.
$releaseparent = true;
}
$hashedkey = cache_helper::hash_key($key, $this->get_definition());
$hashedkey = helper::hash_key($key, $this->get_definition());
$before = microtime(true);
if ($this->nativelocking) {
$lock = $this->get_store()->acquire_lock($hashedkey, $this->get_identifier());
Expand All @@ -153,14 +157,25 @@ public function acquire_lock($key) {
if ($lock) {
$this->locks[$hashedkey] = $lock;
if (MDL_PERF || $this->perfdebug) {
\core\lock\timing_wrapper_lock_factory::record_lock_data($after, $before,
$this->get_definition()->get_id(), $hashedkey, $lock, $this->get_identifier() . $hashedkey);
\core\lock\timing_wrapper_lock_factory::record_lock_data(
$after,
$before,
$this->get_definition()->get_id(),
$hashedkey,
$lock,
$this->get_identifier() . $hashedkey
);
}
$releaseparent = false;
return true;
} else {
throw new moodle_exception('ex_unabletolock', 'cache', '', null,
'store: ' . get_class($this->get_store()) . ', lock: ' . $hashedkey);
throw new moodle_exception(
'ex_unabletolock',
'cache',
'',
null,
'store: ' . get_class($this->get_store()) . ', lock: ' . $hashedkey
);
}
} finally {
// Release the parent lock if we acquired it, then threw an exception.
Expand All @@ -178,7 +193,7 @@ public function acquire_lock($key) {
* someone else has the lock.
*/
public function check_lock_state($key) {
$key = cache_helper::hash_key($key, $this->get_definition());
$key = helper::hash_key($key, $this->get_definition());
if (!empty($this->locks[$key])) {
return true; // Shortcut to save having to make a call to the cache store if the lock is held by this process.
}
Expand All @@ -198,7 +213,7 @@ public function check_lock_state($key) {
*/
public function release_lock($key) {
$loaderkey = $key;
$key = cache_helper::hash_key($key, $this->get_definition());
$key = helper::hash_key($key, $this->get_definition());
if ($this->nativelocking) {
$released = $this->get_store()->release_lock($key, $this->get_identifier());
} else {
Expand All @@ -224,7 +239,7 @@ public function release_lock($key) {
*/
protected function ensure_cachelock_available() {
if ($this->cachelockinstance === null) {
$this->cachelockinstance = cache_helper::get_cachelock_for_store($this->get_store());
$this->cachelockinstance = helper::get_cachelock_for_store($this->get_store());
}
}

Expand Down Expand Up @@ -328,3 +343,8 @@ public function delete_many(array $keys, $recurse = true) {
return parent::delete_many($keys, $recurse);
}
}

// Alias this class to the old name.
// This file will be autoloaded by the legacyclasses autoload system.
// In future all uses of this class will be corrected and the legacy references will be removed.
class_alias(application_cache::class, \cache_application::class);
Loading

0 comments on commit b92008c

Please sign in to comment.