Caching: Disposing of expired items

Topics: Caching Application Block
Feb 21, 2008 at 8:12 AM
Edited Feb 21, 2008 at 8:14 AM
I want to use the CachingApplicationBlock to handled items that must be "Closed/Disposed" when they are expired.

However, if a client is using the item at the time it's expired and removed from the cache, then I can't let the cache ICacheItemRefreshAction handler close the item as that would cause the client currently using it to fail. So I'm thinking I have to implement some kind of reference counting in my cached items and ensure that both the cache and clients 'release' the items with the final release actually doing the Close.

My question is, is the Cache already doing something clever in this area so I don't need to?

I see from the docs on Marking and Sweeping the following statements:

"During marking, BackgroundScheduler makes a copy of the hash table and examines each cache item in it to see if it can be expired. It locks the item while it is doing this. If an item is eligible for expiration, BackgroundScheduler sets a flag in the cache item.

During sweeping, BackgroundScheduler re-examines each flagged CacheItem to see if it has been accessed since it was flagged. If it has been accessed, the item is kept in the cache."

I'm not really sure here what it means by 'accessed'? Does it just mean some client asked the cache for the item or does it mean some client called some business method on the cached item?