Method RegisterCacheNotification
RegisterCacheNotification(String, CacheDataNotificationCallback, EventType, EventDataFilter)
Registers cache notification EventType of type item added, updated or removed against specified key in cache.
Declaration
void RegisterCacheNotification(string key, CacheDataNotificationCallback callback, EventType eventType, EventDataFilter eventDataFilter = EventDataFilter.None)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Unique key to identify the cache item. |
CacheDataNotificationCallback | callback | The CacheDataNotificationCallback that is invoked when specified EventType is triggered against specified key in cache. |
EventType | eventType | Tells whether the event is to be raised on item added, updated or removed. |
EventDataFilter | eventDataFilter | Tells whether to receive metadata, data with metadata or none when a notification is triggered. |
Examples
Following example demonstrates how to register item added, updated or removed notification against a key in cache. First create an ItemCallback
ItemCallback(string key, CacheEventArg cacheEventArgs)
{
...
}
Then register the Key Notification
ICache cache = CacheManager.GetCache("demoCache");
cache.MessagingService.RegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated, EventDataFilter.DataWithMetadata);
RegisterCacheNotification(IEnumerable<String>, CacheDataNotificationCallback, EventType, EventDataFilter)
Registers cache notification EventType of type item added, updated or removed against specified keys in cache.
Declaration
void RegisterCacheNotification(IEnumerable<string> keys, CacheDataNotificationCallback callback, EventType eventType, EventDataFilter eventDataFilter = EventDataFilter.None)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | keys | IEnumerable list of keys to identify the cache item. |
CacheDataNotificationCallback | callback | The CacheDataNotificationCallback that is invoked when specified EventType is triggered against specified keys in cache. |
EventType | eventType | Tells whether the event is to be raised on item added, updated or removed. |
EventDataFilter | eventDataFilter | Tells whether to receive metadata, data with metadata or none when a notification is triggered. |
Remarks
Only single notification is registered against duplicate keys in keys
.
Examples
Following example demonstrates how to register item added, updated or removed notification against multiple keys in cache. First create an ItemCallback
ItemCallback(string key, CacheEventArg cacheEventArgs)
{
...
}
Then register the Key Notification
ICache cache = CacheManager.GetCache("demoCache");
List<string> keys = new List<string>()
{
"Product0",
"Product1",
"Product2"
};
cache.MessagingService.RegisterCacheNotification(keys, new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.DataWithMetadata);
RegisterCacheNotification(CacheDataNotificationCallback, EventType, EventDataFilter)
Registers cache notification EventType of type item added, updated or removed against specified keys in cache.
Declaration
CacheEventDescriptor RegisterCacheNotification(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter eventDataFilter = EventDataFilter.None)
Parameters
Type | Name | Description |
---|---|---|
CacheDataNotificationCallback | callback | The CacheDataNotificationCallback that is invoked when specified EventType is triggered in cache. |
EventType | eventType | Tells whether the event is to be raised on Item Added, Updated or Removed. |
EventDataFilter | eventDataFilter | Tells whether to receive metadata, data with metadata or none when a notification is triggered. |
Returns
Type | Description |
---|---|
CacheEventDescriptor | Instance of CacheEventDescriptor required to |
Remarks
Client application can show interest in receiving events if an item is added, update or removed from the cache. As soon as the item is added, updated or removed from the cache, the client application is notified and actions can be taken accordingly.
Examples
Following example demonstrates how to register Item added, updated or removed notification in cache. First create an ItemCallback
ItemCallback(string key, CacheEventArg e)
{
...
}
Then register the Cache Notification
ICache cache = CacheManager.GetCache("demoCache");
CacheEventDescriptor descriptor = cache.MessagingService.RegisterCacheNotification(new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);