Remove a Cache Notification Callback (Windows Server AppFabric Caching)
Windows Server AppFabric allows your cache-enabled application to receive cache notifications. After you add a cache notification callback, the application continues to receive cache notifications until you remove the callback. This topic describes how to remove a cache notification callback. For more information about cache notifications in general, see Cache Notifications (Windows Server AppFabric Caching).
Use the RemoveCallback method to remove a cache notification callback. To identify the notification, this method requires the DataCacheNotificationDescriptor object that was returned when you added the callback. To facilitate this requirement, declare your DataCacheNotificationDescriptor object at a scope that is accessible to the code in your application and that adds the callback and the code in the application that removes the callback. The DataCacheNotificationDescriptor object returned to the method invoked by the cache notification can also be used to remove a callback.
For your application to use notifications, you need to enable them on a named cache. Use the
To remove a callback cache notification
Declare the DataCacheNotificationDescriptor object you use to add a callback at a scope that is accessible to the code that will remove the callback.
Use the RemoveCallback method to remove the cache notification callback. Use the appropriate DataCacheNotificationDescriptor object for the nd parameter.
In this example, the cache client and three DataCacheNotificationDescriptor objects are declared at the class level so that they can be accessed by methods that add and remove callbacks.
//define variables for class DataCache myTestCache; DataCacheNotificationDescriptor ndCacheLvlAllOps; DataCacheNotificationDescriptor ndRegionLvlAllOps; DataCacheNotificationDescriptor ndItemLvlAllOps;
This example shows a method that uses the RemoveCallback method to remove the callbacks corresponding to all three DataCacheNotificationDescriptor objects from the previous example.