Fix for PEAR Cache_Container_db.php
| From: | Lorenzo Alberton | Date: | Thu, 31 Oct 2002 20:04:46 +0000 |
| Subject: | Fix for PEAR Cache_Container_db.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-10398@lists.php.net to get a copy of this message | ||
31/10/2002 21.04.46
This fixes a possible error with garbageCollection(), plus
makes it more portable (does NOT rely on mysql's NOW() function).
Just replace garbageCollection() method in Cache/Container/db.php
with the following one:
======================================================
function garbageCollection($maxlifetime)
{
$this->flushPreload();
$query = 'DELETE FROM ' . $this->cache_table
.' WHERE (expires <= ' . time()
.' AND expires > 0) OR changed <= '. time() -
$maxlifetime;
$res = $this->db->query($query);
$query = 'SELECT sum(length(cachedata)) as CacheSize FROM '
. $this->cache_table;
$cachesize = $this->db->GetOne($query);
//if cache is to big.
if ($cachesize > $this->highwater)
{
//find the lowwater mark.
$query = 'SELECT length(cachedata) as size, changed FROM '
. $this->cache_table .' ORDER BY changed DESC';
$res = $this->db->query($query);
$numrows = $this->db->numRows($res);
$keep_size = 0;
while ($keep_size < $this->lowwater && $numrows--) {
$entry = $res->fetchRow(DB_FETCHMODE_ASSOC);
$keep_size += $entry['size'];
}
//delete all entries, which were changed before the
"lowwwater mark" $query = 'DELETE FROM '
. $this->cache_table .' WHERE changed<='
. ($entry['changed'] ? $entry['changed'] : 0);
$res = $this->db->query($query);
if (DB::isError($res)) {
return new Cache_Error('DB::query failed: '
. DB::errorMessage($res), __FILE__, __LINE__);
}
}
}
======================================================
Regards,
Lorenzo Alberton
P.S. for Sebastian (or another Cache mantainer): could you include
the "mdb_container" in PEAR::Cache package?
You can find it at this address:
http://utenti.lycos.it/pearzone/
Thank you
---
[Quipo ISP - Questa E-mail e' stata controllata dal programma Declude Virus]
[Quipo ISP - This E-mail was scanned for viruses by Declude Virus]