# How to fix caching

**URL:** <https://www.ruby-forum.com/t/how-to-fix-caching/126271>\
**Category:** Rails\
**Created:** [January 16, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/how-to-fix-caching/126271 "2008-01-16T21:59:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![katsnelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ba8739/32.png) [@katsnelson](https://www.ruby-forum.com/u/katsnelson)\
**Post date:** [January 16, 2008, 9:59pm UTC](https://www.ruby-forum.com/t/how-to-fix-caching/126271/1 "2008-01-16T21:59:49Z")

</div>

Hi all,

Basically I need to turn off caching on 100%, but maybe something else  
will help.

I have a next problem -

in main layout:  
\<% if current\_user and current\_user != :false %\>

\<% else %\>

\<% end %\>

if I login all works fine, I see “Hi user”, but when I press logout  
link, page redirected to “/”, and I see same “Hi user” text. (when I  
reload page with ctrl+F5 page reloaded to valid, with “login please”  
text)  
Server returns 304, but how this can possible? page must be with other  
content.

I use next tags in layout -

and put next cofig into the \config\environments\ -  
config.cache\_classes = false  
config.action\_controller.perform\_caching = false

I see this bug in WEBrick (dev) and in Mongrel (production), with same  
configs and templates.

How I can say to browser always reload a html? or to ROR - not use 304  
status, always re-render html?

---

<div class="post-metadata">

**Author:** ![katsnelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ba8739/32.png) [@katsnelson](https://www.ruby-forum.com/u/katsnelson)\
**Post date:** [January 17, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/how-to-fix-caching/126271/2 "2008-01-17T19:38:58Z")

</div>

He, found a method to fix this:  
in application.rb -

before\_filter … , :set\_header

protected  
def set\_header  
# set modify date to current timestamp  
response.headers[“Last-Modified”] = CGI::rfc1123\_date(Time.now -  
1000)  
# set expiry to back in the past  
# (makes us a bad candidate for caching)  
response.headers[“Expires”] = 0  
# HTTP 1.0 (disable caching)  
response.headers[“Pragma”] = “no-cache”  
# HTTP 1.1 (disable caching of any kind)  
# HTTP 1.1 ‘pre-check=0, post-check=0’ (IE specific)  
response.headers[“Cache-Control”] = “no-cache, no-store,  
must-revalidate, pre-check=0, post-check=0”  
end

Good in IE and FF, but sometimes not helps in Opera.
