ThoKra
ThoKra

Reputation: 3029

Disable SQL Cache temporary in Rails?

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

Upvotes: 34

Views: 15730

Answers (3)

fguillen
fguillen

Reputation: 38802

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

Model.uncached do
  # your code
end

Upvotes: 37

Erik Trautman
Erik Trautman

Reputation: 6029

What specifically worked for me was:

ActiveRecord::Base.connection.clear_query_cache

With credit for good explanations going to this blog post.

Upvotes: 19

ThoKra
ThoKra

Reputation: 3029

Solved with model.connection.clear_query_cache

Upvotes: 31

Related Questions