mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-43033 cache: added stats logging to get_many methods
This commit is contained in:
parent
9b37cd72a2
commit
6dbe2df208
18
cache/classes/helper.php
vendored
18
cache/classes/helper.php
vendored
@ -382,34 +382,40 @@ class cache_helper {
|
||||
/**
|
||||
* Record a cache hit in the stats for the given store and definition.
|
||||
*
|
||||
* @internal
|
||||
* @param string $store
|
||||
* @param string $definition
|
||||
* @param int $hits The number of hits to record (by default 1)
|
||||
*/
|
||||
public static function record_cache_hit($store, $definition) {
|
||||
public static function record_cache_hit($store, $definition, $hits = 1) {
|
||||
self::ensure_ready_for_stats($store, $definition);
|
||||
self::$stats[$definition][$store]['hits']++;
|
||||
self::$stats[$definition][$store]['hits'] += $hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a cache miss in the stats for the given store and definition.
|
||||
*
|
||||
* @internal
|
||||
* @param string $store
|
||||
* @param string $definition
|
||||
* @param int $misses The number of misses to record (by default 1)
|
||||
*/
|
||||
public static function record_cache_miss($store, $definition) {
|
||||
public static function record_cache_miss($store, $definition, $misses = 1) {
|
||||
self::ensure_ready_for_stats($store, $definition);
|
||||
self::$stats[$definition][$store]['misses']++;
|
||||
self::$stats[$definition][$store]['misses'] += $misses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a cache set in the stats for the given store and definition.
|
||||
*
|
||||
* @internal
|
||||
* @param string $store
|
||||
* @param string $definition
|
||||
* @param int $sets The number of sets to record (by default 1)
|
||||
*/
|
||||
public static function record_cache_set($store, $definition) {
|
||||
public static function record_cache_set($store, $definition, $sets = 1) {
|
||||
self::ensure_ready_for_stats($store, $definition);
|
||||
self::$stats[$definition][$store]['sets']++;
|
||||
self::$stats[$definition][$store]['sets'] += $sets;
|
||||
}
|
||||
|
||||
/**
|
||||
|
28
cache/classes/loaders.php
vendored
28
cache/classes/loaders.php
vendored
@ -463,6 +463,20 @@ class cache implements cache_loader {
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->perfdebug) {
|
||||
$hits = 0;
|
||||
$misses = 0;
|
||||
foreach ($fullresult as $value) {
|
||||
if ($value === false) {
|
||||
$misses++;
|
||||
} else {
|
||||
$hits++;
|
||||
}
|
||||
}
|
||||
cache_helper::record_cache_hit($this->storetype, $this->definition->get_id(), $hits);
|
||||
cache_helper::record_cache_miss($this->storetype, $this->definition->get_id(), $misses);
|
||||
}
|
||||
|
||||
// Return the result. Phew!
|
||||
return $fullresult;
|
||||
}
|
||||
@ -1937,7 +1951,19 @@ class cache_session extends cache {
|
||||
if ($hasmissingkeys && $strictness === MUST_EXIST) {
|
||||
throw new coding_exception('Requested key did not exist in any cache stores and could not be loaded.');
|
||||
}
|
||||
|
||||
if ($this->perfdebug) {
|
||||
$hits = 0;
|
||||
$misses = 0;
|
||||
foreach ($return as $value) {
|
||||
if ($value === false) {
|
||||
$misses++;
|
||||
} else {
|
||||
$hits++;
|
||||
}
|
||||
}
|
||||
cache_helper::record_cache_hit($this->storetype, $this->get_definition()->get_id(), $hits);
|
||||
cache_helper::record_cache_miss($this->storetype, $this->get_definition()->get_id(), $misses);
|
||||
}
|
||||
return $return;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user