How can I clear rails cache after deploy to heroku?

前端 未结 7 1979
暖寄归人
暖寄归人 2020-12-13 13:21

I applied cache to my heroku rails app and it works well. But everytime I deploy to heroku, I also want to clear cache automatically.

so I googled and I found this

相关标签:
7条回答
  • 2020-12-13 13:39

    Heroku doesn't currently support a pipeline of actions to occur after deployment. You'll need something like Codeship or TravisCI to create a recipe of steps that happen during deployment

    Disclosure: I am a customer of Codeship.

    0 讨论(0)
  • 2020-12-13 13:51

    Rails has a built in rake task:

    rake tmp:clear
    
    0 讨论(0)
  • 2020-12-13 13:54

    heroku run rake tmp:cache:clear

    http://guides.rubyonrails.org/command_line.html#tmp

    0 讨论(0)
  • 2020-12-13 13:55

    The following should work on cedar:

    heroku run console
    

    ..then wait 5 seconds for heroku console to boot

    Rails.cache.clear
    

    Then you should see the cache clear, and you can quit console. Remember you might have to refresh a few times because your local machine will often cache assets and such in your browser until it makes a fresh request.

    If it happens to be assets that you're caching though, you don't need to go through a manual clear every time you push, you just need to have the asset pipeline set up and make sure all your js/css(less/sass)/static images are being compiled with hashes at the end of their filenames.

    0 讨论(0)
  • 2020-12-13 13:58

    You should be able to create a cache clearing rake task that looks something like this:

    namespace :cache do
      desc "Clears Rails cache"
      task :clear => :environment do
        Rails.cache.clear
      end
    end
    

    and invoke it directly in one command that you can use in your post deploy hook - like so:

    heroku run rake cache:clear
    
    0 讨论(0)
  • 2020-12-13 13:59

    Ruby on Rails has a magical ENV variable called 'RAILS_CACHE_ID'. I set this to the git commit id whenever I deploy: heroku config:set RAILS_CACHE_ID=$CIRCLE_SHA1

    0 讨论(0)
提交回复
热议问题