Clear Memcached on Heroku Deploy

前端 未结 9 1797
旧巷少年郎
旧巷少年郎 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 10:06

    [On the Celadon Cedar Stack]

    -- [Update 18 June 2012 -- this no longer works, will see if I can find another workaround]

    The cleanest way I have found to handle these post-deploy hooks is to latch onto the assets:precompile task that is already called during slug compilation. With a nod to asset_sync Gem for the idea:

    Rake::Task["assets:precompile"].enhance do
      # How to invoke a task that exists elsewhere
      # Rake::Task["assets:environment"].invoke if Rake::Task.task_defined?("assets:environment")
    
      # Clear cache on deploy
      print "Clearing the rails memcached cache\n"
      Rails.cache.clear
    end
    

    I just put this in a lib/tasks/heroku_deploy.rake file and it gets picked up nicely.

提交回复
热议问题