[DG: Open Forum] MySql Query Caching

csev csev at umich.edu
Tue Jun 8 12:41:36 PDT 2010


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


More information about the openforum mailing list