Merge branch 'MDL-39472-master' of git://github.com/sammarshallou/moodle

This commit is contained in:
Dan Poltawski 2013-06-12 13:56:39 +08:00
commit bdce4a9cca
2 changed files with 16 additions and 4 deletions

View File

@ -350,6 +350,11 @@ class cache_helper {
* @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(

View File

@ -912,7 +912,8 @@ class cache implements cache_loader {
* @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
@ -933,10 +934,15 @@ class cache implements cache_loader {
* @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];
@ -976,7 +982,8 @@ class cache implements cache_loader {
* @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;