I've developed a timerjob that adds a lot of XmlDocument objects to the cache of a web application.
I've used this code to add the object to the cache:
Expand|Select|Wrap|Line Numbers
- Cache.Insert(XMLKey, doc, dependency, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(24, 0, 0), System.Web.Caching.CacheItemPriority.Normal, onRemove);
XMLKey --> The cache key used to reference the object
doc --> the XmlDocument object
dependency --> the file dependency for the item to invalid the cache
System.Web.Caching.Cache.NoAbsoluteExpiration --> absolute expiration, in this case the cache should never expire
new TimeSpan(24, 0, 0) --> sliding expiration, in this case the cache should expire after 24 hours
System.Web.Caching.CacheItemPriority.Normal --> Cache item priority
onRemove --> a delegate (CacheItemRemovedCallback) called when the item is removed from the cache for any reason
I need to keep all the objects in cache until their expiration (24 hours), but they are removed automatically after one or two hours!
I use the delegate onRemove to understand the reason of this behavior. In order to do this I print out the CacheItemRemovedReason value and this is REMOVED.
On msdn I've found this about REMOVED as value of CacheItemRemovedReason property:
REMOVED --> The item is removed from the cache by a Remove method call or by an Insert method call that specified the same key.
The point is that I do not call any Insert method with the same key neither any explicit Cache.Remove() method. So I don't understand what causes the removing of all my items. :S
Any idea about this issue? Please, could anyone help me?
Thanks a lot.
Angela