Search code examples
cachingtimeoutappfabric

AppFabric Notification on timeout


I have enabled notification on AppFabric and I'm trying to get notified when an item is removed from the cache after the timeout specified during the Add. Ex :

TimeSpan timeout = new TimeSpan(0,0,10); 
m_cache.Add(OrderId.Text, order, timeout);
m_cache.AddItemLevelCallback(OrderId.Text,DataCacheOperations.RemoveItem,myCacheLvlDelegate);

I put a breakpoint in the "myCacheLvlDelegate" method but it is never reached even after the 10s timeout (test). For test purpose, I have called explicitly

 m_cache.Remove(OrderId.Text); 

after and then the delegate was called !

So the delegate method is only called if I explicitly call the Remove function but not if the timeout expire...

Do you have a solution to get notify after the timeout (the one specified during the add) ?

I need it because I would like to call a webservice after the timeout to refresh data and cache the result again.

Thank you,

Fabrice


Solution

  • What you really need is to be reminded at specific intervals to refresh the Appfabric cache items.

    You could try using the AppFabric cache in conjunction with the Caching block from the Microsoft Enterprise Library. The caching block provides you with the ability to be notified when the item is about to expire. This though will create two caches.

    Store an object identifier in the cache provided by the application block with the necessary timeout interval, while you can "Put" the actual data in the AppFabric cache without a timeout interval. Use the "Put" instead of the "Add" to ensure that you replace the object if it exists else create it.