From 2d70187adec76a4e171fecd0eaa02e9873bd2fc7 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 10 Jun 2020 09:34:25 +0100 Subject: [PATCH] MDL-69005 cache: fix private $store access in loader. --- cache/classes/loaders.php | 2 +- cache/tests/cache_test.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index 6236cb02d50..2b86132987c 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -2097,7 +2097,7 @@ class cache_session extends cache { } $successfullyset = $this->get_store()->set_many($data); if ($this->perfdebug && $successfullyset) { - cache_helper::record_cache_set($this->store, $this->get_definition(), $successfullyset); + cache_helper::record_cache_set($this->get_store(), $this->get_definition(), $successfullyset); } return $successfullyset; } diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index 0e6b203d3d1..a23672ea05b 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -2194,6 +2194,34 @@ class core_cache_testcase extends advanced_testcase { $startstats[$requestid]['stores']['default_request']['hits']); $this->assertEquals(0, $endstats[$requestid]['stores']['default_request']['sets'] - $startstats[$requestid]['stores']['default_request']['sets']); + + $startstats = cache_helper::get_stats(); + + // Check that stores register through set_many. + $this->assertEquals(2, $application->set_many(['setMe1' => 1, 'setMe2' => 2])); + $this->assertEquals(3, $session->set_many(['setMe1' => 1, 'setMe2' => 2, 'setMe3' => 3])); + $this->assertEquals(4, $request->set_many(['setMe1' => 1, 'setMe2' => 2, 'setMe3' => 3, 'setMe4' => 4])); + + $endstats = cache_helper::get_stats(); + + $this->assertEquals(0, $endstats[$applicationid]['stores']['default_application']['misses'] - + $startstats[$applicationid]['stores']['default_application']['misses']); + $this->assertEquals(0, $endstats[$applicationid]['stores']['default_application']['hits'] - + $startstats[$applicationid]['stores']['default_application']['hits']); + $this->assertEquals(2, $endstats[$applicationid]['stores']['default_application']['sets'] - + $startstats[$applicationid]['stores']['default_application']['sets']); + $this->assertEquals(0, $endstats[$sessionid]['stores']['default_session']['misses'] - + $startstats[$sessionid]['stores']['default_session']['misses']); + $this->assertEquals(0, $endstats[$sessionid]['stores']['default_session']['hits'] - + $startstats[$sessionid]['stores']['default_session']['hits']); + $this->assertEquals(3, $endstats[$sessionid]['stores']['default_session']['sets'] - + $startstats[$sessionid]['stores']['default_session']['sets']); + $this->assertEquals(0, $endstats[$requestid]['stores']['default_request']['misses'] - + $startstats[$requestid]['stores']['default_request']['misses']); + $this->assertEquals(0, $endstats[$requestid]['stores']['default_request']['hits'] - + $startstats[$requestid]['stores']['default_request']['hits']); + $this->assertEquals(4, $endstats[$requestid]['stores']['default_request']['sets'] - + $startstats[$requestid]['stores']['default_request']['sets']); } public function test_static_cache() {