We want to be notified when object eviction happens in our project.
I read Cache Notifications (Windows Server AppFabric Caching) (http://msdn.microsoft.com/en-us/library/ee808091.aspx) but don't see an notification associated with object eviction.
Any way we can get to know when object eviction happens?
Sean X WayneThursday, November 04, 2010 9:22 PM
I've the same question. we need to identify item eviction for debugging purposes
Do you mean the remove notification? I've tested it. only initiated remove raises the remove notification.
when object is timed out the notification not raised.
try this code:
cache.AddRegionLevelCallback(IMG_PREFIX, DataCacheOperations.RemoveItem, ItemCallBack);
Console.WriteLine("adding new item"); TimeSpan timeout = new TimeSpan(0, 0, 2); cache.Put("key2", "val2", timeout,IMG_PREFIX); Console.WriteLine("waiting..."); //cache.Remove("key2",IMG_PREFIX); \\only this line raises the remove notification Console.ReadLine(); object a = cache.Get("key2", IMG_PREFIX); Console.ReadLine();
Wednesday, November 23, 2011 11:29 AM
- Edited by ofiry1981 Wednesday, November 23, 2011 11:32 AM
As Gopal mentioned, notifications are raised for both the cases. However, it is important to note that the cache initiated deletes (for expiry and eviction) happen late and on a need basis.
In your Example, if you wait for 2 secs and expect that the callback should come. It might not happen.
For efficiency reasons, the cache initiated deletes happen in bulk and periodically. You can sleep the main thread for 5 mins and then you might be able to see the notification.
Similarly, objects are not evicted unless the cache starts running low on memory. To simulate this you might have to put a lot of objects that do not expire in the cache.
To answer the original question around how to find the evictions : You could look at the total no. of evictions and objects evicted counters in perfmon under AppFabric Caching. These are available at a per cache and per host level and will let you see if forced eviction happened on a cache. I am assuming you need this information for judging if the capacity planning needs to be readjusted. For automation, you could setup a SCOM alert or rule on this perfmon counter.
Thursday, December 22, 2011 8:11 AM
- Proposed as answer by rohit_msfte Thursday, December 22, 2011 8:11 AM