MDL-69005 cache: fix private $store access in loader.
authorPaul Holden <paulh@moodle.com>
Wed, 10 Jun 2020 08:34:25 +0000 (09:34 +0100)
committerPaul Holden <paulh@moodle.com>
Wed, 10 Jun 2020 09:31:47 +0000 (10:31 +0100)
cache/classes/loaders.php
cache/tests/cache_test.php

index 6236cb0..2b86132 100644 (file)
@@ -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;
     }
index 0e6b203..a23672e 100644 (file)
@@ -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() {