RahulOnRails
RahulOnRails

Reputation: 6542

ROR + MVC Disable Browser Cache

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.

Upvotes: 1

Views: 600

Answers (1)

RahulOnRails
RahulOnRails

Reputation: 6542

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

Upvotes: 1

Related Questions