Quantcast
Channel: User Chris W. Rea - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Chris W. Rea for Caching user data in asp.net application

$
0
0

Session may end up being stored out-of-process or in a database, which can make retrieving it expensive. You would likely be using a session database if your application is to be hosted in a server farm, as opposed to a single server. A server farm provides improved scalability and reliability, and it's often a common deployment scenario. Have you thought about that?

Also, when you use Session not in-process, it ends up getting serialized to be sent out-of-process or to a database, and deserialized when retrieved, and you are effectively doing what you describe above:

... updates would be slower since I'd have to re-store the entire dictionary when it changed. ...

.. since, even if you use individual session keys, the entire Session object for a user is serialized and deserialized together (all at once).

Whereas, Cache would be in memory on a particular server in the farm, and therefore much more efficient than going out of process or to the database. However, something in cache on one server might not be in cache on another. So if a user's subsequent request is directed to another server in the farm, the cache on that server might not yet hold any of the user's items.

Nevertheless, I'd suggest you use Cache if you're caching for performance reasons.

p.s. Yes, you're trying too hard. Don't reinvent the wheel unless you really need to. :-)


Viewing all articles
Browse latest Browse all 42

Trending Articles