Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing ActiveRecord cache

I'm building a command line application using ActiveRecord 3.0 (without rails). How do I clear the query cache that ActiveRecord maintains?

like image 351
Prashant Avatar asked Sep 18 '10 07:09

Prashant


People also ask

Does ActiveRecord cache?

ActiveRecord makes accessing your database easy, but it can also help make it faster by its intelligent use of caching.

What does Rails cache clear do?

clear will clear your app cache. In that case rake tmp:cache:clear will just try to remove files from "#{Rails. root}/tmp/cache" but probably won't actually do anything since nothing is probably being cached on the filesystem.

What does ActiveRecord base mean?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.

Can you use ActiveRecord without rails?

One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration. ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.


2 Answers

To a first approximation:

ActiveRecord::Base.connection.query_cache.clear 
like image 79
Barry Kelly Avatar answered Sep 20 '22 00:09

Barry Kelly


Have a look at the method clear_query_cache in http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/QueryCache.html

like image 26
hellvinz Avatar answered Sep 23 '22 00:09

hellvinz