问题描述:

I'm developing a rails application and I need to stop browser's page caching.

I searched through all stackoverflow questions, blogs, and did Google search and I found that most people add the following lines of code to their application controller:

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

I tried the same thing, but for me it works only on some pages, not on all of them. For instance when I log in, if I press the back button, a re-validation request is sent to my server and I prevent it, but when I log out and press the back button, it goes back to the previous page without re-validating. I tested this on Firefox and Chrome and the same thing happens in both browsers.

Here's what I do in my user controller when user presses the log out button:

def logout

session[:user_id] = nil

redirect_to({:controller => 'homepage', :action => 'index'})

end

I'd appreciate it if anyone can help me with this.

相关阅读:
Top