LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Ruby/Rails > Rails caching with cookies

Reply
 
Thread Tools Display Modes
  #1  
Old 04-24-2007, 03:06 PM
baxtr baxtr is offline
Member
 
Join Date: Apr 2007
Posts: 14
Lightbulb Rails caching with cookies

I'm trying to implement cookie based conditional page caching for a rails project. Very similar to this site:
http://www.ethelred.org/articles/200...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
Reply With Quote
  #2  
Old 04-24-2007, 03:17 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
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.
Reply With Quote
  #3  
Old 04-24-2007, 03:20 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
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.
Reply With Quote
  #4  
Old 04-24-2007, 03:36 PM
baxtr baxtr is offline
Member
 
Join Date: Apr 2007
Posts: 14
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.
Reply With Quote
  #5  
Old 04-24-2007, 03:51 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
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.
Reply With Quote
  #6  
Old 04-26-2007, 10:30 AM
baxtr baxtr is offline
Member
 
Join Date: Apr 2007
Posts: 14
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?
Reply With Quote
  #7  
Old 04-26-2007, 10:43 AM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
You need to try a bit harder to stop browser caching pages. consider the following headers.

Code:
Pragma:no-cache
Cache-Control: no-store, no-cache, private, max-stale=0
Expires: 0
Good luck!
Reply With Quote
  #8  
Old 04-26-2007, 11:25 AM
baxtr baxtr is offline
Member
 
Join Date: Apr 2007
Posts: 14
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?
Reply With Quote
  #9  
Old 04-26-2007, 11:38 AM
baxtr baxtr is offline
Member
 
Join Date: Apr 2007
Posts: 14
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.
Reply With Quote
  #10  
Old 04-26-2007, 11:42 AM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
OK, I will check.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:21 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.