Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Rails SQL query caching globally

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?

like image 772
Mohamed Hafez Avatar asked Dec 04 '13 03:12

Mohamed Hafez


2 Answers

Got it! In application.rb:

config.middleware.delete ActiveRecord::QueryCache
like image 52
Mohamed Hafez Avatar answered Sep 28 '22 16:09

Mohamed Hafez


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_query_cache
    ActiveRecord::Base.uncached do
       yield
    end
end
like image 23
Anubhav Singh Avatar answered Sep 28 '22 16:09

Anubhav Singh