Disabling Rails SQL query caching globally

对着背影说爱祢 提交于 2019-12-18 18:55:35

问题


Is there any way to turn off Rails' SQL query caching globally? Or, at the very least, not use it when i enter a transaction block?

Also, does sql query caching only apply to controller actions, or also to rake tasks or background daemons that i write that include Rails and use my models?


回答1:


In Rails 5 we can disable active record query cache using the given function as a middleware.

In application_controller.rb add the given code.

around_action :disable_query_cache

def disable_active_record_query_cache
    ActiveRecord::Base.uncached do
       yield
    end
end



回答2:


Got it! In application.rb:

config.middleware.delete ActiveRecord::QueryCache


来源:https://stackoverflow.com/questions/20366262/disabling-rails-sql-query-caching-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!