views:

25

answers:

1

I heard in an old stackoverflow podcast that they minimized the use of sessions, and that they basically only needed it when posting. How can that be? Don't they need to use some form of sessions on every page view if nothing more than to tell that I'm logged in? How else do they show your username instead of the "Log In" prompt at the top of the screen?

When this type of thing becomes important is when you're persisting your sessions in a database. Now each time you touch your session store, you touch your database. So it would be great if you could avoid it.

You could store all your state in a cookie, but if you care at all about security, then you'll probably want to control state on your server instead.

+2  A: 

I don't know about the podcast you're referring to, but I'm not really sure they were saying what you thought they were saying...

Session data doesn't necessarily have to be written to DB everytime it's touched. You could easily have a cached (using memcached or something similar) intermediary. You could then write the session data to DB every X amount of requests/minutes/writes/whatever.

Sam Day
From what I understand, memcached isn't completely reliable and shouldn't be used in a way that makes it differ from your master data. In other words, it should be just a cache, and no more. So you're right that this would be OK for reads. Writes should be written to both the cache and your persistent data store. In any case, that still requires you to maintain state for each page while logged in, right?
Mike M. Lin
I'm marking this as the answer with the understanding that you obviously do need to maintain some kind of state for logged in users. I suppose it was wishful thinking that it could be avoided.
Mike M. Lin