Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Rails sql query cache hit database?

In my Rails application I see a few 'cache' during SQL query in the server log:

[DEBUG] CACHE (0.0ms) SELECT regions.* FROM regions WHERE regions.name = 'NY' LIMIT 1

I want to know if these caching are done by Rails, or by the MySQL itself? In another word, do these cached queries touch the database layer at all?

like image 403
lulalala Avatar asked Apr 10 '13 02:04

lulalala


People also ask

How does rails query cache work?

Rails provides an SQL query cache which is used to cache the results of database queries for the duration of a request. When Rails encounters the same query again within the same request, it uses the cached result set instead of running the query against the database again.

Does SQL Server cache query results?

SQL Server does not cache the query results, but it caches the data pages it reads in memory. The data from these pages is then used to produce the query result.

Does database cache query?

One way is by caching the results of slow database queries. Caching involves storing the results of your database queries temporarily into memory. Subsequent attempts to query the database will use the stored data instead.

Where is Rails cache stored?

Rails (as of 2.1) provides different stores for the cached data created by action and fragment caches. Page caches are always stored on disk. Rails 2.1 and above provide ActiveSupport::Cache::Store which can be used to cache strings.


1 Answers

The correct answer to the question is "the caching is done by Rails; the queries do not ever get to the database".

like image 92
Tom Harrison Avatar answered Oct 05 '22 07:10

Tom Harrison