Management Level Event Notifications
Note
This feature is only available in NCache Enterprise Edition.
Events can be registered for management operations including cache clear, cache stopped, and member joined/left. Here we describe how to register and unregister management level events.
Prerequisites
- To learn about the standard prerequisites required to work with all NCache client side features please refer to the given page on Client Side API Prerequisites.
- Make sure to enable event notifications using NCache Web Manager.
- For API details, refer to: ICache, CacheItem, MemberJoined, MemberLeft, CacheStopped, CacheCleared.
Cache Clear Event
Some cases may occur in which the application must get notified on cache being cleared. For clear cache event, user has to implement method which has the same signature as CacheClearedCallback. Following method must be implemented in application to perform desired processing when cache cleared is fired.
public void OnCacheCleared()
{
// Perform the tasks after getting the cache clear event
}
For receiving cache clear event, the following line of code must be incorporated in the application:
cache.NotificationService.CacheCleared += OnCacheCleared;
If you do not want to further receive any notifications for cache clear event, add the following line in your application:
cache.NotificationService.CacheCleared -= OnCacheCleared;
Cache Stopped Event
Similar to the cache cleared event, you can also receive notifications when cache is stopped. Following method must be implemented in application to perform processing when cache stopped is fired.
public void OnCacheStopped(string cacheName)
{
// Perform the tasks after getting the cache stopped event
}
For receiving cache stopped event, the following line of code must be incorporated into application:
cache.NotificationService.CacheStopped += OnCacheStopped;
If you do not want to further receive any notifications for cache stopped event, add the following line in your application:
cache.NotificationService.CacheStopped -= OnCacheStopped;
Member Joined Event
The user can also get notified whenever a member joins a cluster. Following method must be implemented in application to perform processing when a member joins a cluster.
public void OnMemberJoined(NodeInfo nodeInfo)
{
// Perform task after Member Joined event gets fired
}
For receiving member joined event, the following line of code must be incorporated into application:
cache.NotificationService.MemberJoined += OnMemberJoined;
If you do not want to further receive any notifications for member joined event, add the following line in your application:
cache.NotificationService.MemberJoined -= OnMemberJoined;
Member Left Event
The user can get notified whenever a member leaves a cluster. Following method must be implemented in application to perform processing when a member leaves a cluster.
public void OnMemberLeft(NodeInfo nodeInfo)
{
// Perform task after Member Left event gets fired
}
For receiving member left event, the following line of code must be incorporated into application:
cache.NotificationService.MemberLeft += OnMemberLeft;
If you do not want to further receive any notifications for member left event, add the following line in your application:
cache.NotificationService.MemberLeft -= OnMemberLeft;
Additional Resources
For a full functioning .NET, Java, and Node.js application executing events, you can use the sample shipped with NCache which is placed on GitHub.
See Also
Cache Level Event Notifications
Item Level Event Notifications
Pub/Sub Messaging
Search Cache with LINQ