ROR + MVC Disable Browser Cache

百般思念 提交于 2020-01-02 21:19:05

问题


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

I found following method,

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

and also for meta tag method.

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

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


回答1:


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.

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

Thanks Goooooogle



来源:https://stackoverflow.com/questions/5469089/ror-mvc-disable-browser-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!