Friday, June 20, 2008

Clearing memcache without restart



Up until now, I always restarted memcache to clear it. However, you can make a rake task to do so:


1 namespace :cache do
2 desc 'Clear memcache'
3 task :clear => :environment do
4 ActionController::Base.cache_store.clear
5 end
6 end



Drop this into /lib/tasks/cache.rake. Now just run the task:


1 rake cache:clear



This only works if you have configured action_controller.cache_store to be memcache.

Have a good weekend!

2 comments:

Igor Petrushenko said...

thank you very much,
it was very helpful for me.

I've experienced problems with cache on stage server.
And clearing cache using you task fixed the problem.

Sincerely,
Igor,
CEO at http://www.mytaskhelper.com

Worm said...

thank you for you task. Very helpfull !