MDL-39062 cache: persist keys now set properly

This commit is contained in:
Sam Hemelryk 2013-05-06 10:35:17 +12:00
parent 07bbbcf174
commit 10aabcb221
2 changed files with 16 additions and 3 deletions

View File

@ -117,6 +117,8 @@ class cache implements cache_loader {
/**
* An array containing just the keys being used in the persist cache.
* This seems redundant perhaps but is used when managing the size of the persist cache.
* Items are added to the end of the array and the when we need to reduce the size of the cache we use the
* key that is first on this array.
* @var array
*/
private $persistkeys = array();
@ -965,6 +967,15 @@ class cache implements cache_loader {
if ($this->perfdebug) {
cache_helper::record_cache_hit('** static persist **', $this->definition->get_id());
}
if ($this->persistmaxsize > 1 && $this->persistcount > 1) {
// Check to see if this is the last item on the persist keys array.
if (end($this->persistkeys) !== $key) {
// It isn't the last item.
// Move the item to the end of the array so that it is last to be removed.
unset($this->persistkeys[$key]);
$this->persistkeys[$key] = $key;
}
}
return $result;
} else {
if ($this->perfdebug) {
@ -989,6 +1000,7 @@ class cache implements cache_loader {
$this->persistcache[$key] = $data;
if ($this->persistmaxsize !== false) {
$this->persistcount++;
$this->persistkeys[$key] = $key;
if ($this->persistcount > $this->persistmaxsize) {
$dropkey = array_shift($this->persistkeys);
unset($this->persistcache[$dropkey]);

View File

@ -30,12 +30,13 @@ $definitions = array(
// Used to store processed lang files.
// The keys used are the component of the string file.
// The persistent max size has been based upon student access of the site.
'string' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'persistent' => true,
'persistentmaxsize' => 3
'persistentmaxsize' => 30
),
// Used to store database meta information.
@ -48,7 +49,7 @@ $definitions = array(
'dbfamily'
),
'persistent' => true,
'persistentmaxsize' => 2
'persistentmaxsize' => 15
),
// Event invalidation cache.
@ -78,7 +79,7 @@ $definitions = array(
// HTML Purifier cache
// This caches the html purifier cleaned text. This is done because the text is usually cleaned once for every user
// and context combo. Text caching handles caching for the combonation, this cache is responsible for caching the
// and context combo. Text caching handles caching for the combination, this cache is responsible for caching the
// cleaned text which is shareable.
'htmlpurifier' => array(
'mode' => cache_store::MODE_APPLICATION,