I have recently added low level caching to a query in Rails 3.2.14 app. In my local I do not see the cached query running twice but its getting logged in production.
I have even checked answers given on this thread where it talks about converting the query result to an array using to_a
method.
@top_quiz_creators = Rails.cache.fetch("/quiz/creators", expires_in: 1.hours) do
Quiz.find_by_sql("some complex query").to_a
end
In mysql-slow.log:
# Time: 170118 8:28:32
# User@Host: db[db] @ ip-xyz.ec2.internal [xyz]
# Query_time: 5.403992 Lock_time: 0.000074 Rows_sent: 5 Rows_examined: 10272991
SET timestamp=1484728112;
How can I stop this query from hitting DB again and again?