Browse Source

- fixed the garbage collection

Added some kind of LRU to delete all entries older than n seconds.
  This fixes the bug that cache entries with lifetime 0 (endless) never
  got removed although if they are no longer used. What's still missing
  is some space limit for cache data.
PHP-4.0.6
Ulf Wendel 25 years ago
parent
commit
457c638bfb
  1. 16
      pear/Cache.php

16
pear/Cache.php

@ -82,7 +82,7 @@ class Cache extends PEAR {
* of seconds.
*
* @var integer
* @see $gc_probability
* @see $gc_probability, $gc_maxlifetime
* @access public
*/
var $gc_time = 1;
@ -93,10 +93,20 @@ class Cache extends PEAR {
* TODO: Add an explanation.
*
* @var integer 0 => never
* @see $gc_time
* @see $gc_time, $gc_maxlifetime
* @access public
*/
var $gc_probability = 1;
/**
* Garbage collection: delete all entries not use for n seconds.
*
* Default is one day, 60 * 60 * 24 = 86400 seconds.
*
* @var integer
* @see $gc_probability, $gc_time
*/
var $gc_maxlifetime = 86400;
/**
* Storage container object.
@ -314,7 +324,7 @@ class Cache extends PEAR {
// time and probability based
if (($force) || ($last_run && $last_run < time() + $this->gc_time) || (rand(1, 100) < $this->gc_probability)) {
$this->container->garbageCollection();
$this->container->garbageCollection($this->gc_maxlifetime);
$last_run = time();
}
} // end func garbageCollection

Loading…
Cancel
Save