[DG: Open Forum] MySql Query Caching

Matthew Jones jonespm at umich.edu
Tue Jun 8 14:22:33 PDT 2010


I've typically avoided mysql query caching because any inserts invalidate
the cache, you still have to connect to the database to get the data, and
many of my apps don't even use a database.

I've really liked this nice standalone cache module that I found a few years
ago described here called SabreCache. [1] I used it for for almost all of my
php projects because of how easy it is to use and how many caching methods
it supports. It is abstract and modular and allows you to use filesystem,
memcache, APC or some other cache you write really easily.

I'd written a "Detector.php" module for it where it would try to use APC by
default, then it would try to use memcache, then if those failed it would
cache on the filesystem in a flat file. I can port that module to the new
version tonight it you wanted to use it. (Noticed I was using an old version
of Sabre and they just released some new code)

Download here: http://code.google.com/p/sabrecache/

[1] http://www.rooftopsolutions.nl/blog/107

On Tue, Jun 8, 2010 at 3:41 PM, csev <csev at umich.edu> wrote:

> I am working on a MySql-only PHP application and have a question about
> query caching.
>
> I have a really simple query - like looking up a user's name from a user id
> - with a perfect index and very simple SQL.
>
> SELECT name FROM Users WHERE UserID='1290090943'
>
> Because of an abstract ORM layer, this might be called several times in a
> single request/response cycle.
>
> My first reaction is to build a caching layer to make sure that the SQL is
> only run once.
>
> But then I thought, "Hey - what about MySql Query Caching?"  If caching is
> done in the driver (i.e. no network traffic to the DB server), then why not
> just rely the MySql query caching and remove the trickier cache code that
> might actually get a bug in it.  Go ahead and send *the exact same SQL* 2-3
> times in a request and have nice, simple code.
>
> i am not worried about caching across request/response - only within the
> same request/response?
>
> Which is the right approach?  Write a cache myself in the DAO layer, or
> just rely on MySql to do it???
>
> /Chuck
> _______________________________________________
> openforum mailing list
> openforum at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/openforum
>
> TO UNSUBSCRIBE: send email to
> openforum-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/openforum/attachments/20100608/985f5d08/attachment.html 


More information about the openforum mailing list