Why can't you set an individual expiry when adding an item to the Session object?
With Cache.Add()
you can set an absolute expiration and sliding expiration. Why can you not do this with Session
?
Why can't you set an individual expiry when adding an item to the Session object?
With Cache.Add()
you can set an absolute expiration and sliding expiration. Why can you not do this with Session
?
Session is not cache. Session is a way to get over the fact that web communication is stateless. A "bucket" is set up per session so you can tie to the session. It times out when the user's session times out (generally 20 minutes after his last page hit).
If you need something to expire, even per user, you need to use cache instead of session. You can use the automagic sugar and vary by the user. Or you can build your own custom abstraction on top of one of the .NET cache objects (I use MemoryCache for local caching). While I am not quick to say "use custom code", there is a benefit with cache if the site is growing in users, as you can one day flip to a distributed cache, like AppFabric caching, nCache (very web friendly) or memcached.