Disabling Rails SQL query caching globally

后端 未结 2 1894
时光说笑
时光说笑 2021-01-04 02:48

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 onl

相关标签:
2条回答
  • 2021-01-04 03:17

    Got it! In application.rb:

    config.middleware.delete ActiveRecord::QueryCache
    
    0 讨论(0)
  • 2021-01-04 03:24

    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
    
    0 讨论(0)
提交回复
热议问题