Re: Module for caching database requests
| From: | Stig S. Bakken | Date: | Sun, 15 Jul 2001 12:33:37 +0000 |
| Subject: | Re: Module for caching database requests | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-766@lists.php.net to get a copy of this message | ||
ekke@chamber.ee wrote:
>
> Hi pearists,
>
> I was just wondering why there isn't a pear module that would cache
> DB requests.
> Is someone developing it and it's well very well-hidden or is it not
> necessery at all?
>
> Anyway, if noone has anything better coming up, one nice day when i get
> myself
> to finish documenting my cache_db module and add error reporting i'll
> put some
> experimental version to cvs. Right now it already has most of the
> features implemented..
>
> How it works?
>
> For storing results i wrote a class DB_fakeResult that stores results of
> queries (taken
> from cache) in a two-dimensional array and operates fetchRow() and
> fetchInto()
> on that.. Only thing not working is tableInfo() function..
>
> the Cache_DB i have is meant to work rather invisibly:
>
> $dbz = DB::Connect ($dsn);
> $db = new Cache_DB ($dbz);
>
> $res = $db->query($q);
> $row = $res->fetchRow();
>
> .. and to try it without the cache you can just replace
> $db = new Cache_DB ($dbz);
> with
> $db = &$dbz;
> or just say
> $db->setCaching(0);
>
> ugh.. if smb want's to test out i put up the modules to
> http://www.chamber.ee/ekke/cachedb.tgz
>
> two files in there then, Cache/DB.php and DB/fakeResult.php
>
> oh, and i've only tested Cache_DB with file cache so far and it's
> hardcoded into the module right now, gotta change that too..
>
> ok then, i'll be waiting for comments..
nice work,
I would like to stick this into DB itself, and make it available like
this:
$dbh = DB::connect("mysql://....", array("cached" => true));
I'd also like to rename your Cache_DB class to DB_Cache_Connection and
DB_fakeResult to DB_Cache_Result.
Do you have a CVS account?
- Stig