NCache 4.4 - Online Documentation

Custom Events Notifications

 
Custom Notifications
 
In multiple clients connected to cache environment, finding the best way to communicate among them is important. Custom Notifications are a special type of notifications which follow publisher and subscriber communication model in which one client application raises custom notification containing notification id and data and the other client applications who register for custom notification will receive it. It is a simple message passing mechanism to control the information flow among clients connected to a cache. In publisher subscriber model, the subscriber application will have to register for custom events and the publisher application raises notification which is sent to subscribers through cache.
 
This type of notification is used in scenarios where the user wants to raise the notification from client application or when he wants to write logic of raising notification on client side rather than cache to decide when to raise notification. For example, if there are multiple applications running and discount price for a specific product is changed on one application, then a custom notification will be raised to notify other client applications about the updated discount price so that they can also update the discount price for that product.   
 
Using Custom Events
 
  • Registering Custom Notification
 
The user can create a custom event according to his/her requirements. This event needs to be registered with CustomEvent. NCache does not raise the custom events on its own, therefore in order to trigger it RaiseCustomEvent method needs to be called. 
 
// Create a target method
Void CacheCustomEvent(object notifId, object data)
{
// do something
}
Product product = new Product();
product.ProductID = 1001;
product.ProductName = "Chai";
product.UnitsInStock = 15;
// Registering custom event
cache.CustomEvent += new CustomEventCallback(CacheCustomEvent);
 
// perform appropriate tasks
//…
//
 
//Raise Custom event upon according to need.
cache.RaiseCustomEvent("mycache", product);
 
Here product must be defined in an independent library so that it is visible to all the applications using custom level notifications.
 
 
 
See Also