【问题标题】:How to disable static file caching in Rails 3 + Thin on Windows如何在 Windows 上的 Rails 3 + Thin 中禁用静态文件缓存
【发布时间】:2012-05-13 09:00:15
【问题描述】:

我的 Rails 3 应用程序中有通过 Thin 提供的静态文件。这些文件没有路径,它们只是通过 url 直接引用。但是,似乎文件正在被缓存。我不确定缓存是由于 Web 服务器 (Thin) 还是由于浏览器 (Chrome) 而发生的。

有没有办法在 Rails 3 或 Windows 上的 Thin 中禁用静态文件缓存?

【问题讨论】:

    标签: ruby-on-rails-3 caching windows-server-2008 thin static-files


    【解决方案1】:

    要强制关闭缓存,请使用config.action_controller.perform_caching = false

    尝试检查的其他选项

    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


    要禁用浏览器缓存,您可以尝试

    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
    

    信用https://stackoverflow.com/a/748646/643500


    对于服务器配置,您可以更改缓存标头,如:

    对于 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

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-10
      • 1970-01-01
      • 2011-10-19
      • 2015-06-07
      相关资源
      最近更新 更多