Alex Rivera | Logout

How to prevent ASP.NET from removing items from cache

Asked 2009-07-07T14:15:04.173
9

I want to permanently add an item to the cache. I am using the following syntax:

HttpContext.Current.Cache.Insert(cacheName, c, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);

I have found out, that ASP.NET still sometimes removes items from the cache.

Any ideas on how to prevent this (in addition to dropping the cache and using Dictionary stored in a static member?

Matra

Edit
Report

1 Answer

2

If you want something stored in memory permanently (i.e. for the life of the AppDomain) then a static field (in your case, a Dictionary<TKey,TValue>) is your best bet.

Once the CLR has loaded the containing type into memory your Dictionary will be held in memory until the AppDomain unloads.

answered 2009-07-07T14:17:39.973

Your Answer