- 论坛徽章:
- 0
|
在http header里设置Expires为一个时间值,可以使浏览器在该时间内都直接使用缓存而不重新请求服务器,响应速度更快并节省流量。Rails默认没有加这个header,但只要稍微修改一下缓存filter即可使action cache生效。
Ruby代码- 1.class ActionController::Caching::Actions::ActionCacheFilter
- 2. def before_with_expires_in(controller)
- 3. should_continue = before_without_expires_in(controller)
- 4. controller.set_expires_in(seconds) if !should_continue && (seconds = @options[:store_options][:expires_in])
- 5. should_continue
- 6. end
- 7. alias_method_chain :before, :expires_in
- 8.end
- 9.
- 10.class ActionController::Base
- 11. def set_expires_in(seconds, options = {})
- 12. expires_in(seconds, options)
- 13. end
- 14.end
复制代码 |
|