Brian Webster
Brian Webster

Reputation: 30855

ASP.NET or PHP: Is Memcached useful for storing user-state information?

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?

Upvotes: 0

Views: 632

Answers (2)

symcbean
symcbean

Reputation: 48357

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.

Upvotes: 1

Coding Flow
Coding Flow

Reputation: 21881

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.

Upvotes: 1

Related Questions