cvs: php4 /pear/Cache/Container dbx.php

From: Date: Sun, 06 May 2001 10:27:54 +0000
Subject: cvs: php4 /pear/Cache/Container dbx.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-115@lists.php.net to get a copy of this message
chregu Sun May 6 03:27:54 2001 EDT Modified files: /php4/pear/Cache/Container dbx.php Log: added low/highwater cache size detection Index: php4/pear/Cache/Container/dbx.php diff -u php4/pear/Cache/Container/dbx.php:1.6 php4/pear/Cache/Container/dbx.php:1.7 --- php4/pear/Cache/Container/dbx.php:1.6 Sat May 5 10:37:29 2001 +++ php4/pear/Cache/Container/dbx.php Sun May 6 03:27:54 2001 @@ -15,7 +15,7 @@ // | Authors: Christian Stocker <chregu@nomad.ch> | // +----------------------------------------------------------------------+ // -// $Id: dbx.php,v 1.6 2001/05/05 17:37:29 chregu Exp $ +// $Id: dbx.php,v 1.7 2001/05/06 10:27:54 chregu Exp $ require_once 'Cache/Container.php'; @@ -50,7 +50,7 @@ * ) * * @author Christian Stocker <chregu@nomad.ch> -* @version $Id: dbx.php,v 1.6 2001/05/05 17:37:29 chregu Exp $ +* @version $Id: dbx.php,v 1.7 2001/05/06 10:27:54 chregu Exp $ * @package Cache */ class Cache_Container_dbx extends Cache_Container { @@ -268,7 +268,36 @@ if (dbx_error($this->db)) return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); + $query = sprintf('select sum(length(cachedata)) as CacheSize from %s', + $this->cache_table + ); + + $res = dbx_query($this->db, $query); + //if cache is to big. + if ($res->data[0][CacheSize] > $this->highwater) + { + //find the lowwater mark. + $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', + $this->cache_table + ); + + $res = dbx_query($this->db, $query); + $keep_size=0; + $i=0; + while ($keep_size < $this->lowwater && $i < $res->rows ) + { + + $keep_size += $res->data[$i][size]; + $i++; } + //delete all entries, which were changed before the "lowwwater mark" + $query = sprintf('delete from %s where changed <= %s', + $this->cache_table, + $res->data[$i][changed] + ); + $res = dbx_query($this->db, $query); + } + } } ?>

« previous php.pear.cvs (#115) next »