Reputation: 3187
I frequently need to run the command "Rails.cache.clear" on Heroku and the only way I have found to do it is to first run "heroku run console" and then run the command. Any way to do it in one step?
Upvotes: 6
Views: 2978
Reputation: 15306
I think this is what you're looking for:
heroku run rails runner -e production Rails.cache.clear
If you don't set the environment, development will be used.
If it's a common task like clearing the cache, make a rake task.
Upvotes: 8
Reputation: 356
This seems to work:
echo "Rails.cache.clear; exit" | heroku run console
Without the exit it seems to hang for some reason, at least for me.
Upvotes: 10
Reputation: 6270
Create a rake task with the command. For example a file lib/tasks/cache.rake
namespace :cache do
desc 'Clear memcache'
task :clear => :environment do
Rails.cache.clear
end
end
Then you can run the command
heroku run rake cache:clear
Upvotes: 4