共用方式為


移除快取通知回呼

Microsoft AppFabric 1.1 for Windows Server 可讓可進行快取的應用程式接收快取通知。新增快取通知回呼之後,應用程式會繼續接收快取通知,直到您移除回呼。此主題說明如何快取通知回呼。如需有關快取通知的詳細資訊,請參閱快取通知 (AppFabric 1.1 快取)

使用 RemoveCallback 方法來移除快取通知回呼。若要識別通知,此方法需要新增回呼時傳回的 DataCacheNotificationDescriptor 物件。為滿足此需求,請將 DataCacheNotificationDescriptor 物件宣告為可供應用程式中的程式碼 (用於新增回呼及移除回呼) 存取的範圍。您也可以使用 DataCacheNotificationDescriptor 物件 (此物件會傳回給快取通知叫用的方法) 來移除回呼。

注意

若要讓您的應用程式使用通知,您必須在具名快取上啟用它們。使用 notificationsEnabled 參數來搭配 New-CacheSet-CacheConfig 命令。如需詳細資訊,請參閱使用 Windows PowerShell 來管理 AppFabric 1.1 快取功能

移除回呼快取通知

  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 PowerShell 來管理 AppFabric 1.1 快取功能

  2012-03-05