删除缓存通知回拨(Windows Server AppFabric 缓存)

Windows Server AppFabric 允许已启用缓存的应用程序接收缓存通知。添加缓存通知回调后,应用程序将继续接收缓存通知,直到您删除回调。本主题介绍如何删除缓存通知回调。有关缓存通知的常规详细信息,请参阅缓存通知(Windows Server AppFabric 缓存)

使用 RemoveCallback 方法删除缓存通知回调。要标识通知,此方法要求提供添加回调时返回的 DataCacheNotificationDescriptor 对象。要便于满足该要求,请在应用程序中添加回调的代码和应用程序中删除回调的代码可以访问的作用域内声明 DataCacheNotificationDescriptor 对象。返回到由缓存通知调用的方法的 DataCacheNotificationDescriptor 对象也可用于删除回调。

备注

为了应用程序能够使用通知,您需要在指定缓存上启用通知。使用带 notificationsEnabled 参数的 New-CacheSet-CacheConfig 命令。有关详细信息,请参阅使用 Windows PowerShell 管理 Windows Server AppFabric 缓存功能

删除回调缓存通知的步骤

  1. 声明用于在将删除回调的代码可以访问的作用域内添加回调的 DataCacheNotificationDescriptor 对象。

  2. 使用 RemoveCallback 方法删除缓存通知回调。对 nd 参数使用适当的 DataCacheNotificationDescriptor 对象。

示例

在本示例中,缓存客户端和三个 DataCacheNotificationDescriptor 对象是在类级别声明的,因此添加和删除回调的方法可以对其进行访问。

'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;

本示例演示了使用 RemoveCallback 方法删除与上一示例中的所有三个 DataCacheNotificationDescriptor 对象对应的回调的方法。

'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);
}

另请参阅

概念

添加缓存通知回拨(Windows Server AppFabric 缓存功能)
添加失败通知回拨(Windows Server AppFabric 缓存)
缓存通知方法(Windows Server AppFabric 缓存)
使用 Windows PowerShell 管理 Windows Server AppFabric 缓存功能

  2011-12-05