Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 827
ThoKra Avatar asked Aug 30 '10 11:08

ThoKra


3 Answers

Solved with model.connection.clear_query_cache

like image 153
ThoKra Avatar answered Nov 07 '22 21:11

ThoKra


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

Model.uncached do
  # your code
end
like image 27
fguillen Avatar answered Nov 07 '22 22:11

fguillen


What specifically worked for me was:

ActiveRecord::Base.connection.clear_query_cache

With credit for good explanations going to this blog post.

like image 17
Erik Trautman Avatar answered Nov 07 '22 21:11

Erik Trautman