/**
* 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;
}
/**
}
}
+ 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;
}
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;
}