ActiveRecord, Sinatra and Query Cache on Heroku
I have a rake task that I run to query my DB on heroku. My initialization for the task use setting Query Cache but I am not seeing any queries cached.
开发者_运维知识库def init(args)
ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.establish_connection(config[args[:environment]])
use ActiveRecord::QueryCache
end
def sometask(args)
init(args)
@foo.each do |f|
x = f.something.find_by_foo_id(foo_id)
end
end
Turns out when I examine the output I see repeatedly: SELECT * FROM foo WHERE foo_id = 1
or whatever. No caching is going on.
How do I force my code to use a cached query with ActiveRecord
?
This gist should help you get what you want -- https://gist.github.com/712114
精彩评论