Rails caching with cookies

#1
I'm trying to implement cookie based conditional page caching for a rails project. Very similar to this site:
http://www.ethelred.org/articles/2006/10/22/conditional-use-of-page-cache-in-rails

Basically non-logged in users get a cached site and logged in users get dynamic content. I have 90% of it working but there seems to be a small problem with the HTTP_COOKIE condition in the rewrite. When a user logs out they still see cached content unless they click the refresh button manually within there browser for each page, or wait about 30 seconds. Any ideas? Here is a copy of my Litespeed vhost rewrite rule.

RewriteCond %{HTTP_COOKIE} !^.*logged_in=yes.*$
RewriteRule ^(.*)/$ $1/index.html [QSA]
RewriteCond %{HTTP_COOKIE} !^.*logged_in=yes.*$
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /dispatch.lsapi [QSA,L]

Thanks,
Dan
 

mistwang

LiteSpeed Staff
#2
LSWS does not cache cookie values, it just use what received in the request.
You can check the cookie value with firefox LiveHeader extension.
Make sure to clear the cookie value when a user logout.
 

mistwang

LiteSpeed Staff
#3
I probably misunderstood your problem.
I think you need to add "no-cache" header in the dynamic response to prevent the browser from caching pages.
 
#4
That was also my first idea. I disabled cache completely within my browser and tried a no-cache header, also tried a few different browsers. I also double checked that the cookie is removed upon logout. Does everything look fine in my RewriteCond? I've been trying to figure out this little problem all day, thanks for the quick response.
 

mistwang

LiteSpeed Staff
#5
There is no problem with the rewrite rules.
Two possibilities, one is that browser cache the page, you can verify it with LiveHeader extension, if browser uses a cached page, there should not be any new request sent. You can verify that at server end with access log as well.

Another possibilities, is browser cache the cookie value, you should be able to verify it with LiveHeader.
You can also turn on rewrite log at server side to verify the rewrite rules.
 
#6
Well I played around with LiveHeaders and you were rite the page is being cached by the browser. I tried adding the no-cache headers to my default rails layout page and it didn't seem to fix the problem. When I notice the problem the page does not refresh and the the browser doesn't even request a page from the server according to liveheaders. Is there anyway to set no-cache in litespeed rather then in my rails app?
 

mistwang

LiteSpeed Staff
#7
You need to try a bit harder to stop browser caching pages. consider the following headers. ;)

Code:
[FONT=Verdana,Arial,Helvetica][SIZE=2]Pragma:no-cache
Cache-Control: no-store, no-cache, private, max-stale=0
Expires: 0
[/SIZE][/FONT]
Good luck! :)
 
#8
Ok the headers seems to work fine in Firefox. However, I was testing with Safari and I just read in Google that Safari ignores caches headers within HTML. Can I try adding the headers to the extra headers field in the Rails context section of Litespeed?
 
#9
I'm not sure this is a bug, but if you put more then one line the Extra Headers field in the Rail context menu, Litespeed fails to restart or startup. One line seems to work fine.
 
#13
Wow, that was fast thanks for the amazing support. I'm in the trial period for the 64-bit linux ent version. We plan on purchasing the ent. edition when were ready to launch the site. Thanks again.
 
Top