diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index dc2b96ab76c..10ad62095cc 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -282,8 +282,8 @@ class cache implements cache_loader { $parsedkey = $this->parse_key($key); // 2. Get it from the static acceleration array if we can (only when it is enabled and it has already been requested/set). $result = false; - if ($this->is_using_persist_cache()) { - $result = $this->get_from_persist_cache($parsedkey); + if ($this->use_static_acceleration()) { + $result = $this->static_acceleration_get($parsedkey); } if ($result !== false) { if (!is_scalar($result)) { @@ -309,8 +309,8 @@ class cache implements cache_loader { if ($result instanceof cache_cached_object) { $result = $result->restore_object(); } - if ($this->is_using_persist_cache()) { - $this->set_in_persist_cache($parsedkey, $result); + if ($this->use_static_acceleration()) { + $this->static_acceleration_set($parsedkey, $result); } } // 4. Load if from the loader/datasource if we don't already have it. @@ -378,14 +378,14 @@ class cache implements cache_loader { $keystofind = array(); // First up check the persist cache for each key. - $isusingpersist = $this->is_using_persist_cache(); + $isusingpersist = $this->use_static_acceleration(); foreach ($keys as $key) { $pkey = $this->parse_key($key); $keysparsed[$key] = $pkey; $parsedkeys[$pkey] = $key; $keystofind[$pkey] = $key; if ($isusingpersist) { - $value = $this->get_from_persist_cache($pkey); + $value = $this->static_acceleration_get($pkey); if ($value !== false) { $resultpersist[$pkey] = $value; unset($keystofind[$pkey]); @@ -408,8 +408,8 @@ class cache implements cache_loader { if ($value instanceof cache_cached_object) { $value = $value->restore_object(); } - if ($value !== false && $this->is_using_persist_cache()) { - $this->set_in_persist_cache($key, $value); + if ($value !== false && $this->use_static_acceleration()) { + $this->static_acceleration_set($key, $value); } $resultstore[$key] = $value; } @@ -506,8 +506,8 @@ class cache implements cache_loader { $data = new cache_ttl_wrapper($data, $this->definition->get_ttl()); } $parsedkey = $this->parse_key($key); - if ($this->is_using_persist_cache()) { - $this->set_in_persist_cache($parsedkey, $data); + if ($this->use_static_acceleration()) { + $this->static_acceleration_set($parsedkey, $data); } return $this->store->set($parsedkey, $data); } @@ -611,7 +611,7 @@ class cache implements cache_loader { } $data = array(); $simulatettl = $this->has_a_ttl() && !$this->store_supports_native_ttl(); - $usestaticaccelerationarray = $this->is_using_persist_cache(); + $usestaticaccelerationarray = $this->use_static_acceleration(); foreach ($keyvaluearray as $key => $value) { if (is_object($value) && $value instanceof cacheable_object) { $value = new cache_cached_object($value); @@ -630,7 +630,7 @@ class cache implements cache_loader { 'value' => $value ); if ($usestaticaccelerationarray) { - $this->set_in_persist_cache($data[$key]['key'], $value); + $this->static_acceleration_set($data[$key]['key'], $value); } } if ($this->perfdebug) { @@ -662,7 +662,7 @@ class cache implements cache_loader { */ public function has($key, $tryloadifpossible = false) { $parsedkey = $this->parse_key($key); - if ($this->is_in_persist_cache($parsedkey)) { + if ($this->static_acceleration_has($parsedkey)) { // Hoorah, that was easy. It exists in the static acceleration array so we definitely have it. return true; } @@ -744,11 +744,11 @@ class cache implements cache_loader { return false; } - if ($this->is_using_persist_cache()) { + if ($this->use_static_acceleration()) { $parsedkeys = array(); foreach ($keys as $id => $key) { $parsedkey = $this->parse_key($key); - if ($this->is_in_persist_cache($parsedkey)) { + if ($this->static_acceleration_has($parsedkey)) { return true; } $parsedkeys[] = $parsedkey; @@ -769,7 +769,7 @@ class cache implements cache_loader { */ public function delete($key, $recurse = true) { $parsedkey = $this->parse_key($key); - $this->delete_from_persist_cache($parsedkey); + $this->static_acceleration_delete($parsedkey); if ($recurse && $this->loader !== false) { // Delete from the bottom of the stack first. $this->loader->delete($key, $recurse); @@ -787,9 +787,9 @@ class cache implements cache_loader { */ public function delete_many(array $keys, $recurse = true) { $parsedkeys = array_map(array($this, 'parse_key'), $keys); - if ($this->is_using_persist_cache()) { + if ($this->use_static_acceleration()) { foreach ($parsedkeys as $parsedkey) { - $this->delete_from_persist_cache($parsedkey); + $this->static_acceleration_delete($parsedkey); } } if ($recurse && $this->loader !== false) { @@ -921,19 +921,44 @@ class cache implements cache_loader { /** * Returns true if this cache is making use of the static acceleration array. * + * @deprecated since 2.6 + * @see cache::use_static_acceleration() * @return bool */ protected function is_using_persist_cache() { + debugging('This function has been deprecated. Please call use_static_acceleration instead', DEBUG_DEVELOPER); + return $this->use_static_acceleration(); + } + + /** + * Returns true if this cache is making use of the static acceleration array. + * + * @return bool + */ + protected function use_static_acceleration() { return $this->staticacceleration; } + /** + * Returns true if the requested key exists within the static acceleration array. + * + * @see cache::static_acceleration_has + * @deprecated since 2.6 + * @param string $key The parsed key + * @return bool + */ + protected function is_in_persist_cache($key) { + debugging('This function has been deprecated. Please call static_acceleration_has instead', DEBUG_DEVELOPER); + return $this->static_acceleration_has($key); + } + /** * Returns true if the requested key exists within the static acceleration array. * * @param string $key The parsed key * @return bool */ - protected function is_in_persist_cache($key) { + protected function static_acceleration_has($key) { // This method of checking if an array was supplied is faster than is_array. if ($key === (array)$key) { $key = $key['key']; @@ -953,10 +978,23 @@ class cache implements cache_loader { /** * Returns the item from the static acceleration array if it exists there. * + * @deprecated since 2.6 + * @see cache::static_acceleration_get * @param string $key The parsed key * @return mixed|false The data from the static acceleration array or false if it wasn't there. */ protected function get_from_persist_cache($key) { + debugging('This function has been deprecated. Please call static_acceleration_get instead', DEBUG_DEVELOPER); + return $this->static_acceleration_get($key); + } + + /** + * Returns the item from the static acceleration array if it exists there. + * + * @param string $key The parsed key + * @return mixed|false The data from the static acceleration array or false if it wasn't there. + */ + protected function static_acceleration_get($key) { // This method of checking if an array was supplied is faster than is_array. if ($key === (array)$key) { $key = $key['key']; @@ -975,7 +1013,7 @@ class cache implements cache_loader { } $result = $data; } else if ($data->has_expired()) { - $this->delete_from_persist_cache($key); + $this->static_acceleration_delete($key); $result = false; } else { if ($data instanceof cache_cached_object) { @@ -1009,11 +1047,25 @@ class cache implements cache_loader { /** * Sets a key value pair into the static acceleration array. * + * @deprecated since 2.6 + * @see cache::static_acceleration_set * @param string $key The parsed key * @param mixed $data * @return bool */ protected function set_in_persist_cache($key, $data) { + debugging('This function has been deprecated. Please call static_acceleration_set instead', DEBUG_DEVELOPER); + return $this->static_acceleration_set($key, $data); + } + + /** + * Sets a key value pair into the static acceleration array. + * + * @param string $key The parsed key + * @param mixed $data + * @return bool + */ + protected function static_acceleration_set($key, $data) { // This method of checking if an array was supplied is faster than is_array. if ($key === (array)$key) { $key = $key['key']; @@ -1038,10 +1090,23 @@ class cache implements cache_loader { /** * Deletes an item from the static acceleration array. * + * @deprecated since 2.6 + * @see cache::static_acceleration_delete() * @param string|int $key As given to get|set|delete * @return bool True on success, false otherwise. */ protected function delete_from_persist_cache($key) { + debugging('This function has been deprecated. Please call static_acceleration_delete instead', DEBUG_DEVELOPER); + return $this->static_acceleration_delete($key); + } + + /** + * Deletes an item from the static acceleration array. + * + * @param string|int $key As given to get|set|delete + * @return bool True on success, false otherwise. + */ + protected function static_acceleration_delete($key) { unset($this->staticaccelerationarray[$key]); if ($this->staticaccelerationsize !== false) { $dropkey = array_search($key, $this->staticaccelerationkeys); @@ -2083,7 +2148,7 @@ class cache_session extends cache { * * @return bool */ - protected function is_using_persist_cache() { + protected function use_static_acceleration() { return false; } } diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index 0b0f578c4ef..6295f55ee9b 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -1577,33 +1577,33 @@ class core_cache_testcase extends advanced_testcase { $this->assertEquals(array('b' => 'B', 'c' => 'C'), $cache->get_many(array('b', 'c'))); // Make sure all items are in static acceleration array. - $this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertEquals('B', $cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); + $this->assertEquals('A', $cache->phpunit_static_acceleration_get('a')); + $this->assertEquals('B', $cache->phpunit_static_acceleration_get('b')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); // Add new value and make sure it is in cache and it is in array. $this->assertTrue($cache->set('d', 'D')); - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); $this->assertEquals('D', $cache->get('d')); // Now the least recent accessed item (a) is no longer in acceleration array. - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertEquals('B', $cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertEquals('B', $cache->phpunit_static_acceleration_get('b')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); // Adding and deleting element. $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->delete('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); $this->assertFalse($cache->has('a')); // Make sure "purge" deletes from the array as well. $cache->purge(); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); + $this->assertFalse($cache->phpunit_static_acceleration_get('c')); + $this->assertFalse($cache->phpunit_static_acceleration_get('d')); + $this->assertFalse($cache->phpunit_static_acceleration_get('e')); // Check that the array holds the last accessed items by get/set. $this->assertTrue($cache->set('a', 'A')); @@ -1611,11 +1611,11 @@ class core_cache_testcase extends advanced_testcase { $this->assertTrue($cache->set('c', 'C')); $this->assertTrue($cache->set('d', 'D')); $this->assertTrue($cache->set('e', 'E')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); /** @var cache_phpunit_application $cache */ $cache = cache::make('phpunit', 'accelerated2'); @@ -1628,28 +1628,28 @@ class core_cache_testcase extends advanced_testcase { $this->assertTrue($cache->set('d', 'D')); $this->assertTrue($cache->set('e', 'E')); // Current keys in the array: c, d, e. - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); $this->assertEquals('A', $cache->get('a')); // Current keys in the array: d, e, a. - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); - $this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); + $this->assertEquals('A', $cache->phpunit_static_acceleration_get('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); + $this->assertFalse($cache->phpunit_static_acceleration_get('c')); // Current keys in the array: d, e, a. $this->assertEquals(array('c' => 'C'), $cache->get_many(array('c'))); // Current keys in the array: e, a, c. - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); - $this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); + $this->assertEquals('A', $cache->phpunit_static_acceleration_get('a')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); + $this->assertFalse($cache->phpunit_static_acceleration_get('d')); $cache = cache::make('phpunit', 'accelerated3'); @@ -1661,25 +1661,25 @@ class core_cache_testcase extends advanced_testcase { $this->assertTrue($cache->set('c', 'C')); $this->assertTrue($cache->set('d', 'D')); $this->assertTrue($cache->set('e', 'E')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertEquals('C', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertFalse($cache->phpunit_static_acceleration_get('b')); + $this->assertEquals('C', $cache->phpunit_static_acceleration_get('c')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); $this->assertTrue($cache->set('b', 'B2')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertEquals('B2', $cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertEquals('D', $cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertEquals('B2', $cache->phpunit_static_acceleration_get('b')); + $this->assertFalse($cache->phpunit_static_acceleration_get('c')); + $this->assertEquals('D', $cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); $this->assertEquals(2, $cache->set_many(array('b' => 'B3', 'c' => 'C3'))); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('a')); - $this->assertEquals('B3', $cache->phpunit_get_directly_from_staticaccelerationarray('b')); - $this->assertEquals('C3', $cache->phpunit_get_directly_from_staticaccelerationarray('c')); - $this->assertFalse($cache->phpunit_get_directly_from_staticaccelerationarray('d')); - $this->assertEquals('E', $cache->phpunit_get_directly_from_staticaccelerationarray('e')); + $this->assertFalse($cache->phpunit_static_acceleration_get('a')); + $this->assertEquals('B3', $cache->phpunit_static_acceleration_get('b')); + $this->assertEquals('C3', $cache->phpunit_static_acceleration_get('c')); + $this->assertFalse($cache->phpunit_static_acceleration_get('d')); + $this->assertEquals('E', $cache->phpunit_static_acceleration_get('e')); $cache = cache::make('phpunit', 'accelerated4'); $this->assertInstanceOf('cache_phpunit_application', $cache); @@ -1690,7 +1690,7 @@ class core_cache_testcase extends advanced_testcase { $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->set('a', 'A')); $this->assertTrue($cache->set('a', 'A')); - $this->assertEquals('A', $cache->phpunit_get_directly_from_staticaccelerationarray('a')); + $this->assertEquals('A', $cache->phpunit_static_acceleration_get('a')); $this->assertEquals('A', $cache->get('a')); } } diff --git a/cache/tests/fixtures/lib.php b/cache/tests/fixtures/lib.php index 7f241f44a5b..e6ecbe0f407 100644 --- a/cache/tests/fixtures/lib.php +++ b/cache/tests/fixtures/lib.php @@ -258,9 +258,9 @@ class cache_phpunit_application extends cache_application { * @param string $key * @return false|mixed */ - public function phpunit_get_directly_from_staticaccelerationarray($key) { + public function phpunit_static_acceleration_get($key) { $key = $this->parse_key($key); - return $this->get_from_persist_cache($key); + return $this->static_acceleration_get($key); } } diff --git a/cache/upgrade.txt b/cache/upgrade.txt index 351519f9184..38f9c4b21bc 100644 --- a/cache/upgrade.txt +++ b/cache/upgrade.txt @@ -8,6 +8,12 @@ Information provided here is intended especially for developers. * The persistentmaxsize option has been renamed to staticaccelerationsize. It does the same thing. * cache_definition::should_be_persistent has been deprecated. Please call cache_definition::use_static_acceleration instead. * cache_definition::get_persistent_max_size has been deprecated. Please call cache_definition::get_static_acceleration_size instead. +* cache::is_using_persist_cache() has been deprecated. Please call cache::use_static_acceleration() +* cache::is_in_persist_cache() has been deprecated. Please call cache::static_acceleration_has() +* cache::get_from_persist_cache() has been deprecated. Please call cache::static_acceleration_get() +* cache::set_in_persist_cache() has been deprecated. Please call cache::static_acceleration_set() +* cache::delete_from_persist_cache() has been deprecated. Please call cache::static_acceleration_delete() +* If you have any custom cache loaders you will need to rename these methods if you have overriden them and adjust any calls you may have made to them. === 2.5 === * cleanup method renamed to instance_deleted. diff --git a/lib/db/caches.php b/lib/db/caches.php index 57c3e37580e..f2445e234d0 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -30,7 +30,7 @@ $definitions = array( // Used to store processed lang files. // The keys used are the revision, lang and component of the string file. - // The persistent max size has been based upon student access of the site. + // The static acceleration size has been based upon student access of the site. // NOTE: this data may be safely stored in local caches on cluster nodes. 'string' => array( 'mode' => cache_store::MODE_APPLICATION, @@ -46,7 +46,7 @@ $definitions = array( 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, - 'persistent' => true, + 'staticacceleration' => true, ), // Used to store database meta information. @@ -115,7 +115,7 @@ $definitions = array( 'simplekeys' => true, // The course id the groupings exist for. 'simpledata' => true, // Array of stdClass objects containing only strings. 'staticacceleration' => true, // Likely there will be a couple of calls to this. - 'persistmaxsize' => 2, // The original cache used 1, we've increased that to two. + 'staticaccelerationsize' => 2, // The original cache used 1, we've increased that to two. ), // Used to cache calendar subscriptions.