I'm using a .net Memory Cache with .NET 4.0 and c#, I want my application to be notified when an item is removed (so I can write that it has been removed to a log file or notify the UI, that the item is removed).
Is there anyway to do this.
I'm using System.Runtime.Caching.MemoryCache not System.Web.Caching
EDIT: If you're using the
System.Runtime.Caching.MemoryCache
there is a callback on theCacheItemPolicy
object for deletion, as well as one for update.Initial answer
When inserting data in the .net cache for the
System.Web.Caching
namespace you have the option to set a callback to be notified of removalThere is also a signature for the
Insert
method that lets you specify a callback to be notified before the item is removed