NOTE: This feature is not available in NCache Express and Professional edition.
NCache provides the MemberLeftCallback delegate. It defines the signature to use when you write event handlers to respond when a node leaves the cluster.
Notify application when a node leaves
-
Add the following namespaces in your application for using events:
using Alachisoft.NCache.Web.Caching;
using Alachisoft.NCache.Runtime;
-
Create an event handler procedure that will be called by MemberLeftCallback when a node leaves the cache cluster. For example, the following code prints the node information when a node leaves the cache cluster.
public void OnCacheMemberLeft(NodeInfo nodeinfo)
{
Console.Writeline("Node Left With IPAddress" +
nodeinfo.IPAddress.ToString() +
"and port number:" + nodeinfo.Port);
}
Note: The parameter of type NodeInfo is defined in namespace Alachisoft.NCache.Web.Net. It returns the IPAddress and Port number of the leaving node.
-
Create an instance of the MemberLeftCallback delegate that calls the event handler. The following code calls the method created in step two.
Cache _cache = NCache.InitializeCache("myCache");
_cache.MemberLeft = new MemberLeftCallback(this.OnCacheMemberLeft);
When a node leaves the cache cluster, the OnCacheMemberLeft method is called.
See Also