cvs: php4 /pear/Cache/Container phplib.php
| From: | Christian Stocker | Date: | Sat, 05 May 2001 17:22:20 +0000 |
| Subject: | cvs: php4 /pear/Cache/Container phplib.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-113@lists.php.net to get a copy of this message | ||
chregu Sat May 5 10:22:20 2001 EDT
Modified files:
/php4/pear/Cache/Container phplib.php
Log:
low/highwater mark detection of cache size done.
Index: php4/pear/Cache/Container/phplib.php
diff -u php4/pear/Cache/Container/phplib.php:1.12 php4/pear/Cache/Container/phplib.php:1.13
--- php4/pear/Cache/Container/phplib.php:1.12 Wed May 2 11:49:33 2001
+++ php4/pear/Cache/Container/phplib.php Sat May 5 10:22:20 2001
@@ -16,7 +16,7 @@
// | Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: phplib.php,v 1.12 2001/05/02 18:49:33 uw Exp $
+// $Id: phplib.php,v 1.13 2001/05/05 17:22:20 chregu Exp $
require_once 'Cache/Container.php';
@@ -50,7 +50,7 @@
*
*
* @author Ulf Wendel <ulf.wendel@phpdoc.de>, Sebastian Bergmann
<sb@sebastian-bergmann.de>
-* @version $Id: phplib.php,v 1.12 2001/05/02 18:49:33 uw Exp $
+* @version $Id: phplib.php,v 1.13 2001/05/05 17:22:20 chregu Exp $
* @package Cache
* @see save()
*/
@@ -118,7 +118,7 @@
*/
function Cache_Container_phplib($options = "") {
if (is_array($options))
- $this->setOptions($options, array_merge($this->allowed_options),
array("db_class", "db_file", "db_path", "local_file",
"local_path")));
+ $this->setOptions($options, array_merge($this->allowed_options,
array("db_class", "db_file", "db_path", "local_file",
"local_path")));
if (!$this->db_class)
return new Cache_Error("No database class specified.", __FILE__, __LINE__);
@@ -151,7 +151,7 @@
$id,
$group
);
-
+ $this->db->query($query);
return array($this->db->f("expires"),
$this->decode($this->db->f("cachedata")),
$this->db->f("userdata"));
} // end func fetch
@@ -218,13 +218,42 @@
$this->flushPreload();
$this->db->query(
- sprintf("DELETE FORM %s WHERE (expires <= %d AND expires > 0) OR
changed <= (NOW() - %d)",
+ sprintf("DELETE FROM %s WHERE (expires <= %d AND expires > 0) OR
changed <= (NOW() - %d)",
$this->cache_table,
time(),
$maxlifetime
)
);
+ //check for total size of cache
+ $query = sprintf('select sum(length(cachedata)) as CacheSize from %s',
+ $this->cache_table
+ );
+
+ $this->db->query($query);
+ $this->db->Next_Record();
+ $cachesize = $this->db->f("CacheSize");
+ //if cache is to big.
+ if ($cachesize > $this->highwater)
+ {
+ //find the lowwater mark.
+ $query = sprintf('select length(cachedata) as size, changed from %s order by
changed DESC',
+ $this->cache_table
+ );
+ $this->db->query($query);
+
+ $keep_size=0;
+ while ($keep_size < $this->lowwater && $this->db->Next_Record() )
+ {
+ $keep_size += $this->db->f("size");
+ }
+ //delete all entries, which were changed before the "lowwwater mark"
+ $query = sprintf('delete from %s where changed <=
'.$this->db->f("changed"),
+ $this->cache_table
+ );
+
+ $this->db->query($query);
+ }
} // end func garbageCollection
}
?>