Asp.net - deleting cache object at session end?

Instead of putting the whole dictionary in the cache as one cache entry, put each element in the cache as an entry. Then you can give each element a sliding time window of the session timeout time, and let the system handle expiration.

Up vote 0 down vote favorite share g+ share fb share tw.

I have a wrapper class for Caching (CachingBL) where I store users that are currently signed in (some of their session info). In CachingBL wrapper there is actually a dictionary of users, and I am putting that dictionary in cache like this: HttpContext.Current.Cache. Insert(...): At the session end I would need to access to the cache like this: var cacheBL = (CacheBL)HttpContext.Current.Cache.

Get("MyCache_CacheSlot"); But the problem is that HttpContext. Current is empty, so I cannot access the Cache object. The Cache itself is not empty (tested), but I can't figure out how to access it at Session_End.

Asp.net caching asp. Net-caching link|improve this question edited Dec 21 '09 at 16:44p. Campbell28.8k858125 asked Dec 21 '09 at 16:40the berserker213415 73% accept rate.

1 But session and cache entry could expire at different times. I need exactly the same mapping - all the users that are in session need to have the cache entry. At the moment the session expires, user needs to be removed from cache.

– the berserker Dec 22 '09 at 9:45.

Inside the Session_OnEnd event there is no way to get access to the HttpContext. Current because there is no current request. But you do have access to the session state which includes all session variables.

So if you us a session variable to store your token to the key name of the sessions cache slot ("MyCache_CacheSlot" in your example), you will be able to release that cache inside the Session_OnEnd event.

You can use System.Web.HttpRuntime. Cache to access the cache statically.

System.Web.SessionState. HttpSessionState is the one I should use instead of HttpContext.Current.

HttpSessionState provides access to the session. Not the Cache so you haven't actually answered your own question. – Shane Courtrille Jun 15 '11 at 20:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions