Clear Memcached on Heroku Deploy

前端 未结 9 1741
旧巷少年郎
旧巷少年郎 2020-12-13 09:18

What is the best way to automatically clear Memcached when I deploy my rails app to Heroku?

I\'m caching the home page, and when I make changes and redeploy, the pag

9条回答
  •  抹茶落季
    2020-12-13 09:47

    Since the heroku gem is deprecated, an updated version of Solomons very elegant answer would be to save the following code in lib/tasks/heroku_deploy.rake:

    namespace :deploy do
        task :production do
            puts "deploying to production"
            system "git push heroku"
            puts "clearing cache"
            system "heroku run rake cache:clear"
            puts "done"
        end
    end
    
    namespace :cache do
      desc "Clears Rails cache"
      task :clear => :environment do
        Rails.cache.clear
      end
    end
    

    then instead of git push heroku master you type rake deploy:production in command line. To just clear the cache you can run rake cache:clear

提交回复
热议问题