Home > Code > Caching mySql Queries – mySql Cache for a Query

Caching mySql Queries – mySql Cache for a Query

One of my servers is receiving a large number of full text queries so I’ve been thinking of ways to minimize the load. The current CPU load is quite low but for future scalability it makes sense to whip up a caching system. Fortunately I read the mySql manual before inventing my own wheel:

When in use, the query cache stores the text of a SELECT query together with the corresponding result that was sent to the client. If the identical query is received later, the server retrieves the results from the query cache rather than parsing and executing the query again.

C’est facile!

query_cache_size = 1000000

query_cache_type = 1

From: MySQL Query Cache

Categories: Code Tags:
  1. Matt
    July 14th, 2006 at 07:02 | #1

    Don’t forget that the cache requires an absolute context match, i.e. “select * from table” and “SELECT * from table” will cause 2 separate cache entries, as will extra space characters, etc. For this reason you should either (a) be extra careful when creating queries or (b) run the query through a quick “eregi_replace” so strip out extra blank spaces and capitalise keywords not between single-quotes