ROR + MVC禁用浏览器缓存 [英] ROR + MVC Disable Browser Cache

查看:92
本文介绍了ROR + MVC禁用浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来禁用整个 Ruby On Rails MVC网站的浏览器缓存。

I am looking for method to disable Browser Cache for entire Ruby On Rails MVC Website

我发现了以下方法,

Response.Cache.SetExpires(DateTime.Now.AddSeconds(5));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);

以及元标记方法。

<meta http-equiv="PRAGMA" content="NO-CACHE">

但是我正在寻找一种简单的方法来禁用整个网站的浏览器缓存。

But i am looking for simple method, to disable browser cache for entire website.

推荐答案

朋友,在Google上进行了长时间的搜索。我对此有一个解决方案。我不知道这是更好还是最好。但是我的问题解决了。

Friends, After a long search on Google. I got one solution for this. I do not know Is this better or best. But My problem is resolved.

在application_controller.rb中的代码下面添加..

Add below your code in 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

感谢Goooooogle

Thanks Goooooogle

这篇关于ROR + MVC禁用浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆