Disable SQL Cache temporary in Rails?

2019-02-11 22:11发布

I'm currently creating a Rails app with some cronjobs etc, but I have some problems because the sql is cached by Rails.

So anyone know how to disable the SQL Cache in Rails? Not globally, but for this code. Really don't want to create one method for every model, so is there anyway to just disable it temporary?

Terw

3条回答
Anthone
2楼-- · 2019-02-11 22:44

Another approach is using ActiveRecord::QueryCache::ClassMethods#uncached

Model.uncached do
  # your code
end
查看更多
我只想做你的唯一
3楼-- · 2019-02-11 22:50

Solved with model.connection.clear_query_cache

查看更多
一夜七次
4楼-- · 2019-02-11 23:04

What specifically worked for me was:

ActiveRecord::Base.connection.clear_query_cache

With credit for good explanations going to this blog post.

查看更多
登录 后发表回答