1

I have static files which are servered up via Thin in my Rails 3 application. There isn't a route for these files, they are just directly referenced via url. However, it seems as though the file is being cached. I'm not sure if the caching is occuring due to the web server (Thin) or due to the browser (Chrome).

Is there a way to disable static file caching in Rails 3 or Thin on Windows?

Edward J. Stembler
  • 1,932
  • 4
  • 30
  • 53

1 Answers1

0

To force caching to be off use config.action_controller.perform_caching = false

Other options to try and check

config.serve_static_assets = false

config.static_cache_control = "public, max-age=0"

config.assets.digest = false

https://devcenter.heroku.com/articles/rack-cache-memcached-static-assets-rails31#serve_static_assets


To disable browsers from caching you can try

application_controller.rb..

  before_filter :set_cache_buster

  def set_cache_buster
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end

credit https://stackoverflow.com/a/748646/643500


For server configuration, you can change cache header like:

For Apache:

<LocationMatch "^/assets/.*$">
  Header unset ETag
  FileETag None
  # RFC says only cache for 1 year
  ExpiresActive On
  ExpiresDefault "access plus 1 year"
</LocationMatch>

http://guides.rubyonrails.org/asset_pipeline.html

Community
  • 1
  • 1
Sully
  • 14,672
  • 5
  • 54
  • 79