NCache 4.4 - Online Documentation

NCache Management API

 
NCache management API is a set of programmable method calls that enables the user to perform basic management operations on out-proc caches without using either NCache Manager or NCache tools. Management API in some cases relies on the client configuration files to perform an operation, whereas in some cases it is self-sufficient to execute a request.
 
Include following namespace in project
 
using Alachisoft.NCache.Web.Management;
 
Starting Cache Using API Calls
 
Start Cache methods enable the user to start an out-proc cache on the specified server. In case of failure Management Exception is thrown by the cache. In this example, the user need to specify cache and server name to start a node.
 
//precondition: Cache has been registered but not initialized.
string cacheName="mycache";
string serverName="...."; // specify the server where cache is registered
try
{
    CacheManager.StartCache(cacheName, serverName);
}
catch (ManagementException ex)
{
    //thrown if no cache exists or server name is invalid
}    
 
Stopping Cache Using API Calls
 
Stop Cache methods are used to stop a cache on a particular server. If no server is specified the method would read information from client configuration file. If the method fails to stop the cache or fails to find information regarding the cache, Management Exception is thrown. If called from the client node, the first server listed in the client configuration file associated with the cache will be stopped. 
 
This example stops cache on an already started node. Cache and server name to stop cache on given node need to be specified.
 
try
{
    CacheManager.StopCache(cacheName, serverName);
}
catch (ManagementException ex)
{
    // handle exception
}
 
Viewing Cache Status Using API Calls
 
GetCacheHealth method enables the user to view the status of cache server nodes. This method call returns a CacheHealth object against every call. The user will need to include the following namespace in his/her project for CacheHealth class.
 
Alachisoft.NCache.Runtime.CacheManagement
 
In this example the user only needs to specify the cache name, the API uses client configuration file to connect to the server nodes and collect information; the initial node can also be specified. In case of failure of connection or incorrect cache name, the NCache would throw Management Exception.
 
try
{
    CacheHealth cacheHealth = CacheManager.GetCacheHealth(cacheName);
}
catch (ManagementException)
{
    // handle exception
}
 
Viewing  List of Clients Connected with a Cache
 
GetCacheClient method enables the user to get a list of all connected clients on a server node at a given time. This method returns a dictionary containing server names and list of all client nodes connected at that given time. The user should  include “Alachisoft.NCache.Runtime.CacheManagement” namespace in his/her project for the resultant dictionary of this method call. 
 
In this example only the cache name needs to be specified, the API uses client configuration file to connect to the server nodes and collects information;the initial node can also be specified. In case of failure of connection or incorrect cache name, NCache would throw Management Exception.
 
try
{
    //Returns list of all clients connected with cache servers
    Dictionary<ServerNode, List<CacheClient>> clientList = CacheManager.GetCacheClients(cacheName);
}
catch (ManagementException ex)
{
    // handle exception
 
}
 
See Also