Skip to content

Commit

Permalink
Merge branch 'MDL-39472-m24' of git://github.com/sammarshallou/moodle…
Browse files Browse the repository at this point in the history
… into MOODLE_24_STABLE
  • Loading branch information
danpoltawski committed Jun 12, 2013
2 parents 0ad1608 + e5bc3e3 commit 6e74e42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cache/classes/helper.php
Expand Up @@ -345,6 +345,11 @@ public static function purge_by_event($event) {
* @param string $definition
*/
protected static function ensure_ready_for_stats($store, $definition) {
// This function is performance-sensitive, so exit as quickly as possible
// if we do not need to do anything.
if (isset(self::$stats[$definition][$store])) {
return;
}
if (!array_key_exists($definition, self::$stats)) {
self::$stats[$definition] = array(
$store => array(
Expand Down
15 changes: 11 additions & 4 deletions cache/classes/loaders.php
Expand Up @@ -912,7 +912,8 @@ protected function is_using_persist_cache() {
* @return bool
*/
protected function is_in_persist_cache($key) {
if (is_array($key)) {
// This method of checking if an array was supplied is faster than is_array.
if ($key === (array)$key) {
$key = $key['key'];
}
// This could be written as a single line, however it has been split because the ttl check is faster than the instanceof
Expand All @@ -933,10 +934,15 @@ protected function is_in_persist_cache($key) {
* @return mixed|false The data from the persist cache or false if it wasn't there.
*/
protected function get_from_persist_cache($key) {
if (is_array($key)) {
// This method of checking if an array was supplied is faster than is_array.
if ($key === (array)$key) {
$key = $key['key'];
}
if (!$this->persist || !array_key_exists($key, $this->persistcache)) {
// This isset check is faster than array_key_exists but will return false
// for null values, meaning null values will come from backing store not
// the persist cache. We think this okay because null usage should be
// very rare (see comment in MDL-39472).
if (!$this->persist || !isset($this->persistcache[$key])) {
$result = false;
} else {
$data = $this->persistcache[$key];
Expand Down Expand Up @@ -976,7 +982,8 @@ protected function get_from_persist_cache($key) {
* @return bool
*/
protected function set_in_persist_cache($key, $data) {
if (is_array($key)) {
// This method of checking if an array was supplied is faster than is_array.
if ($key === (array)$key) {
$key = $key['key'];
}
$this->persistcache[$key] = $data;
Expand Down

0 comments on commit 6e74e42

Please sign in to comment.