Reputation: 374
I have a problem that only occurs on my production box. Works fine in DEV and TEST environments. The problem is the page that is served up is cached - doesnt reflect recent changes I have made. The odd part is it doesnt happen all the time. If I clear the browser cache it might work until I close out the browser and then open and reload the app - then it fails again. Sometimes I can load the page fine in IE, Chrome and Firefox. But if I close out Firefox and open it again- it can then fail with the old page. Not sure if it matters, but the file I am trying to change is a haml file. Here is what I have tried so far:
On the production box itself:
rm -rm tmp/cache/assets
rake assets:clobber
rake assets:precompile
rake assets:clean
rake tmp:cache:clear
rails tmp:clear
rails restart
After 'rails restart' it seems to work for a little while. Again, works in all browsers until I close out Firefox a few times...then reverts back to the old file. Also worked fine for a couple of open/close of Chrome - then reverted to old file. I found another issue here where someone set no-cache. In application_controller.rb
before_filter :set_cache_buster
def set_cache_buster
response.headers["Cache-Control"] = "no-cache, no-store"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
In config/environments/production.rb:
config.cache_classes = false
config.cache_store = false
config.action_controller.perform_caching = false
If I try to run 'Rails.cache.clear' from the console I get:
NoMethodError: undefined method 'clear' for false:FalseClass
This is a very odd issue. Anyone think of any other things I could try?
Upvotes: 0
Views: 811
Reputation: 165456
If your production environment is in the cloud there is no guarantee about the state of the filesystem or how many instances will be running, unless you specifically set it up that way. One request might go to instance A while the next request might go to instance B. Each instance has its own filesystem and cache.
Furthermore, cloud instances are regularly moved around and you will lose your cache.
Instead of caching on the filesystem, you'll need to use a cache server such as memcached or Redis. Or make your production environment run on a single server, but that does not scale.
Upvotes: 1