$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)) {
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.
$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]);
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;
}
$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);
}
}
$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);
'value' => $value
);
if ($usestaticaccelerationarray) {
- $this->set_in_persist_cache($data[$key]['key'], $value);
+ $this->static_acceleration_set($data[$key]['key'], $value);
}
}
if ($this->perfdebug) {
*/
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;
}
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;
*/
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);
*/
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) {
/**
* 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 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'];
/**
* 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'];
}
$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) {
/**
* 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'];
/**
* 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);
*
* @return bool
*/
- protected function is_using_persist_cache() {
+ protected function use_static_acceleration() {
return false;
}
}
$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'));
$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');
$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');
$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);
$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'));
}
}
* @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);
}
}
* 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.
// 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,
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
- 'persistent' => true,
+ 'staticacceleration' => true,
),
// Used to store database meta information.
'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.