Arun Agrawal’s Blog

Ruby on Rails Developer

Query Cache in Rails

By default Rails do Query cache. Whenever it execute find it enables the query cache. You can enable manually by wrapping up in cache block.
Post.cache do
  puts Post.first
  puts Post.first
  puts Post.first
end
Your development.log looks like:
Post Load (1.0ms) SELECT * FROM posts LIMIT 1
CACHE (0.0ms) SELECT * FROM posts LIMIT 1
CACHE (0.0ms) SELECT * FROM posts LIMIT 1