*/
class SqlBagOStuff extends BagOStuff {
var $table;
+ var $lastexpireall = 0;
function SqlBagOStuff($tablename = 'objectcache') {
$this->table = $tablename;
function get($key) {
/* expire old entries if any */
- $this->expireall();
+ $this->garbageCollect();
$res = $this->_query(
"SELECT value,exptime FROM $0 WHERE keyname='$1'", $key);
die( 'abstract function SqlBagOStuff::_fromunixtime() must be defined' );
}
+ function garbageCollect() {
+ $nowtime = time();
+ /* Avoid repeating the delete within a few seconds */
+ if ( $nowtime > ($this->lastexpireall + 1) ) {
+ $this->lastexpireall = $nowtime;
+ $this->expireall();
+ }
+ }
+
function expireall() {
/* Remove any items that have expired */
- $now=$this->_fromunixtime(time());
+ $now = $this->_fromunixtime( time() );
$this->_query( "DELETE FROM $0 WHERE exptime<'$now'" );
}