I have a script that updates the Postgres database with new data. I'd like to clear all cached pages after the script completes. but I can't seem to get this to take effect without completely restarting the Heroku server
I have tried without success:
Rails.cache.clear => ["/app/tmp/cache/bootsnap-compile-cache", "/app/tmp/cache/bootsnap-load-path-cache"]
rails tmp:cache:clear
rails assets:clean
config.cache_store is not set explicitly for production, (I've seen mixed information as to what cache is being used by default)
I have ensured that there is no caching in the browser (by disabling caching in dev tools and bypassing the service worker)
I'm using Heroku with ruby 2.5.3, rails 5.2.1.1, and actionpack-action_caching 1.2.0
I added logging to the action which only logs the first time a page is accessed after a restart
Update: I removed action caching and instead better optimized the SQL quarries by using eager loading.
I didn't properly understand how Heroku's dyno's work.
Heroku spines up new VM's (dynos) when using heroku run bash
, causing any cache clearing not to affect the webserver running on the existing dyno. To ssh into running dynos you'll want to use heroku ps:exec
As you can see here, default cache store in production is mem_cache_store. Therefore, you should be able to clear it in different ways, without restarting the sever. Maciej Mensfeld wrote a blog about these ways. I personally use flush_all
command in the cache server if Rails.cache.clear
does not make effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With