views:

58

answers:

2

This question may expose my ignorance as a web developer, but that wouldn't exactly be a bad thing for me now would it?

I have the need to store user-state information. Examples of information that I need to store per user. (define user: unauthenticated visitor)

  1. User arrived to the site from google/bing/yahoo
  2. User utilized the search feature (true/false)
  3. List of previous visited product pages on current visit

It is my understanding that I could store this in the view state, but that causes a problem with page load from the end-users' perspective because a significant amount of non-viewable information is being transferred to and from the end-users even though the server is the only side that needs the info.

On a similar note, it is my understanding that the session state can be used to store such information, but does not this also result in the same information being transferred to the user and stored in their cookie? (Not quite as bad as viewstate, but it does not feel ideal).

This leaves me with either a server-only-session storage system or a mem-caching solution.

Is memcached the only good option here?

+1  A: 

Memcached is good for read often/write rarely key/value data, it is a cache as the name implies. e.g. if you are serving up product info that changes infrequently you store it in memcached so you are not querying the database repeatedly for semi static data. You should use session state to store your info, the only thing that will be passed to and fro is the session identifier, not the actual data, that stays on the server.

Ben Robinson
Does this require end-users to have cookies turned on though?
hamlin11
It depends on what framework you are using e.g. PHP and asp.net support cokiesless session state by appending the session identifier onto the URL.
Ben Robinson
+1  A: 

Items 1 and 2 seem to be logging information - i.e. there's no obvious requirement to refer back them, unless you want to keep their search terms. So just write it to a log somewhere and forget about it?

I could store this in the view state

I'm guessing that's a asp.net thing - certainly it doesn't mean anything to me, so I can't comment.

it is my understanding that the session state can be used to store such information

Yes - it would be my repository of choice for item 3.

does not this also result in the same information being transferred to the user and stored in their cookie?

No - a session cookie is just a handle to data stored server-side in PHP (and every other HTTP sesion imlpementation I've come across).

This leaves me with either a server-only-session storage system or a mem-caching solution

memcache is only really any use as a session storage substrate.

Whether you should use memcache as your session storage substrate....on a single server, there's not a lot of advantage here - although NT (IIRC) uses fixed size caches/buffers (whereas Posix/Unix/Linux will use all available memory) I'd still expect most the session I/O to be to memory rather than disk unless your site is overloaded. The real advantage is if you're running a cluster (but in that scenario you might want to consider something like Cassandra).

IME, sessions are not that great of an overhead, however if you want to keep an indefinite history of the activity in a session, then you should overflow the data (or keep it seperate from) the session to prevent it getting too large.

C.

symcbean
In summary, it appears that you are proposing the use of the session state to store "session" information. Makes sense, but even though the end-user is only storing an identifier in their cookie, does this require the end-user to have cookies enabled in order for us to store information in their session state? Do I lose out on all visitors who have cookies turned off?
hamlin11
No, you can propagate the session handle via the URL - but ensuring this always is populated with the correct value is very difficult. I would suggest crafting some javascript to detect if cookies are disabled and ask the user nicely to enable them if they're not.
symcbean