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.

Note

For your application to use notifications, you need to enable them on a named cache. Use the notificationsEnabled parameter with the New-Cache or Set-CacheConfig commands. For more information, see Using Windows PowerShell to Manage Windows Server AppFabric Caching Features.

To remove a callback cache notification

  1. Declare the DataCacheNotificationDescriptor object you use to add a callback at a scope that is accessible to the code that will remove the callback.

  2. Use the RemoveCallback method to remove the cache notification callback. Use the appropriate DataCacheNotificationDescriptor object for the nd parameter.

Example

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
Dim myTestCache As DataCache
Dim ndCacheLvlAllOps As DataCacheNotificationDescriptor
Dim ndRegionLvlAllOps As DataCacheNotificationDescriptor
Dim ndItemLvlAllOps As DataCacheNotificationDescriptor
//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.

'remove cache notification callbacks
Public Sub RemoveNotificationCallbacks()
    myTestCache.RemoveCallback(ndCacheLvlAllOps)
    myTestCache.RemoveCallback(ndRegionLvlAllOps)
    myTestCache.RemoveCallback(ndItemLvlAllOps)
End Sub
//remove cache notification callbacks
public void RemoveNotificationCallbacks()
{
    myTestCache.RemoveCallback(ndCacheLvlAllOps);
    myTestCache.RemoveCallback(ndRegionLvlAllOps);
    myTestCache.RemoveCallback(ndItemLvlAllOps);
}

See Also

Concepts

Add a Cache Notification Callback (Windows Server AppFabric Caching)
Add a Failure Notification Callback (Windows Server AppFabric Caching)
Cache Notifications Methods (Windows Server AppFabric Caching)
Using Windows PowerShell to Manage Windows Server AppFabric Caching Features