Re: Fix for PEAR Cache_Container_db.php
| From: | Lorenzo Alberton | Date: | Fri, 08 Nov 2002 09:19:00 +0000 |
| Subject: | Re: Fix for PEAR Cache_Container_db.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-10610@lists.php.net to get a copy of this message | ||
08/11/2002 9.53.08
> > Hi Lorenzo
> >
> > Can you make a unified diff patch file out of this and not sending
> > the whole code. It makes it much easier to see, what you changed
> > and i don't have to do copy&paste and fighting with some funny
> > whitespacehandling of my mailclients :)
Of course, if only could I understand how to make a diff in the format
used here with cygwin... My Linux box is dead at the moment, so I have
to do everyth with cygwin until I find some time to set Linux up again..
Could you tell me what syntax I'm supposed to use with diff? Tnx
To sum up the changes I made:
- I moved the last $res = $this->db->query($query);
a level up because it was mis-placed, outside the right parenthesis
- I substituted mysql's NOW() function with a simple time(), so it's
more portable between different dbms.
- I changed the $entry assignment in the while loop because last time
it was called, it overwrote the value otherwise needed in the query
just after the while loop ( $entry is set to "null" in the last
loop, making the later use of $entry[changed] senseless...).
Attached: a txt with the replacement, waiting for the diff... So you
can start playing with it without worring about whitespacehandling :-)
> > Concerning your MDB Container, the problem I have with it, is just
> > that we need then to make a dependency on MDB and MDB will be
> > installed if you want PEAR::Cache and this is some kind of not-
> > expecting for everyone who doesn't use the MDB Container... Are
> > there any possiblities, to make a dependency just a "suggested
> > additional packages needed" :) I'm sure someone of you guys thought
> > about that before.
> [Lukas Smith wrote:]
> nah you just kick out the dependency on DB :-)
>
> actually I don't think that there is anything in the pear installer to
> handle optional dependencies for when there are multiple containers
> available.
>
> Regards,
> Lukas
Actually I think Lukas answered for me... I really don't see what
differences should be done between db_container and mdb_container
wrt dependencies... they both need sth else, so why a different
treatment for the two? If db needs a dependency, so mdb would also do,
otherwise don't set any dependency for either of them...
However I think that "soft dependencies", as introduced by Stig,
are the way to go...
> > Thanks
> >
> > chregu
Tnx to you!
Lorenzo
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__); } } }
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__); } } }