NYCPHP Meetup

NYPHP.org

[nycphp-talk] PEAR DB_Cache is dead?

Michael mogmios at mlug.missouri.edu
Thu Aug 12 17:30:18 EDT 2004


>umm, such as getting data out of a filesystem cache instead of contacting the db.
>
>Anyway:  what do you guys recommend? I often use shared servers where db
>performance sometimes sucks -- more than likely because of sloppy
>application coding -- and I like to be part of the solution by caching
>frequently requested but rarely changing data. I see Cache and Cache_Lite
>are out there but I'm fishing for expert opinion.
>  
>
Can you run a db or SQLlite on your local server? Rather than resort to 
flat files I like to keep a small cache db with a copy of any recent 
data in it. Such that my code tries the cache db first and if there 
isn't a copy of the data there then it connects to the regular db and 
tries running the query. Obviously each result from the regular db is 
cached after use and periodically I run a command on the cache to erase 
outdated data. I've found this is especially useful for working with 
paged data such as search results. This way the results won't change as 
the user flips pages of results which is something I find annoying when 
using websites. My db layout is pretty simple usually. A field for the 
query, a field for the timestamp, and a field for the result. Then I 
create one such row for each result for that query.

Another option I sometimes use is writing an XML-RPC interface to each 
of my db queries and then letting my app talk to the db through that 
interface. Because XML-RPC usually runs over HTTP you can easily set the 
cache life of the result. Then simply run a proxy (such as Squid) 
between your app and your db. I rather like this method because it 
removes all db logic from my apps and means I don't have to have any 
open ports to my db at all. Just let the db server's local web server 
talk to the db. It also means that if you want to create other 
interfaces to the db that you can write those interfaces in any language 
that has an XML-RPC library and you don't have to duplicate any queries.

-- 
Michael <mogmios at mlug.missouri.edu>
http://kavlon.org




More information about the talk mailing list