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
You cannot ever completely prevent something from being removed from the ASP.NET Cache (i.e. the HttpContext.Current.Cache object) and this is very much by design.
Please see the section in the MSDN Article ASP.NET Caching Overview called "Automatic Data Removal", which gives the most pertinent information regarding items being removed from the cache.
It states:
It's for this reason (Scavenging, if no other) that you can never absolutely rely upon an item that you may have previously placed in the Cache and explicitly marked it with NoSlidingExpiration and NoAbsoluteExpiration, and possibly even marked it as a high priority item, as still being there in the Cache at a later point in time.