• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Client Side API Programming
  • Management API
Show / Hide Table of Contents
  • Programmer's Guide
  • Setting Up Development Environment
    • .NET
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Java
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Python
      • Client API Prerequisites
    • Node.js
      • Client API Prerequisites
  • Client Side API Programming
    • Error Handling
    • Troubleshooting
    • Cache Keys and Data
    • How to Connect to Cache
    • Basic Operations - An Overview
      • Add Data
      • Update/Insert Data
      • Retrieve Data
      • Remove Data
    • Groups
      • Overview
      • Add/Update Data with Groups
      • Retrieve Data with Groups
      • Remove Data with Group
      • Search Group Data Using SQL
      • Delete Group Data Using SQL
    • Tags
      • Overview
      • Add/Update Data with Tags
      • Retrieve Data with Tags
      • Remove Data with Tags
      • Search Tag Data Using SQL
      • Delete Tag Data Using SQL
    • Named Tags
      • Overview
      • Add/Update Data with Named Tags
      • Remove Data with Named Tags
      • Search Data with Named Tags Using SQL
      • Delete Data with Named Tags Using SQL
    • Expirations
      • Overview
      • Absolute Expiration
      • Sliding Expiration
    • Data Dependency
      • Key Dependency
      • Multi-Cache Dependency
    • Dependency on Database
      • SQL Server
      • Oracle
      • OleDB with Polling
      • CLR Procedures in SQL Server
    • Dependency on External Source
      • File Dependency
      • Custom Dependency
      • Aggregate Dependency
    • Locks
      • Types of Locking
      • Pessimistic Locking
      • Optimistic Locking
    • SQL Query
      • Overview
      • Define Indexes Programmatically
      • Query with ExecuteReader and ExecuteScalar
      • Delete Data with ExecuteNonQuery
      • SQL Reference
    • LINQ Query
      • Overview
      • LINQ Query for Objects
      • LINQ Reference
    • Data Structures
      • Overview
      • List
      • Queue
      • Set
      • Dictionary
      • Counter
      • Invalidation Attributes
      • Searchable Attributes
      • Query on Data Structures
      • Remove from Data Structure
    • Events
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Topics
      • Publish Messages
      • Subscribe to a Topic
      • Pub/Sub Events
    • Continuous Query
      • Overview
      • Use Continuous Query
    • Stream Processing
      • Add/Update Stream Data
      • Retrieve Stream Data
    • JSON
      • Overview
      • Use JSON Objects
      • Query JSON Data
    • Security API
      • Login with Credentials
    • Management API
    • Clear Cache
    • Error Logging
    • Location Affinity
  • Server-side API Programming
    • Loader and Refresher
      • Overview
      • Implement Loader and Refresher
      • Components of Loader/Refresher
    • Data Source Providers
      • Read-through
        • Implement Read-through
        • Use Read-through
      • Write-through
        • Implement Write-through
        • Use Write-through
        • Use Write-behind
    • Custom Dependency
      • Implement Extensible Dependency
      • Implement Bulk Extensible Dependency
      • Implement Notify Extensible Dependency
    • Bridge Conflict Resolver
    • Entry Processor
      • Overview
      • Implement Entry Processor
    • MapReduce
      • Overview
      • Implement MapReduce
      • Use MapReduce
    • MapReduce Aggregator
      • Overview
      • Implement and Use Aggregator
    • Compact Serialization
  • Client Side Features
    • ASP.NET Core Caching
      • Session Storage
        • Session Provider
        • IDistributedCache
        • Sessions Usage
        • Multi-site Session Provider
        • Session Sharing with ASP.NET
      • SignalR
        • NCache Extension for SignalR Core
      • Response Caching
        • Configure and Use
        • Configure with IDistributedCache
      • Data Caching
        • NCache API
        • IDistributedCache API
      • Data Protection Provider
        • Configure
    • Java Web App Caching
      • Web Sessions
        • Overview
        • Configure App
          • Add Maven Dependencies
          • Deploy Application
        • Multi-site Sessions
    • Node.js App Caching
      • Web Sessions
    • ASP.NET Caching Benefits and Overview
      • ASP.NET Session State Provider Properties
      • Multi-region ASP.NET Session State Provider Configuration
      • Session Sharing between ASP.NET and ASP.NET Core
      • ASP.NET SignalR Backplane
        • NCache Extension for SignalR
      • ASP.NET View State Caching
        • View State Content Optimization Configuration
        • Group View State with Sessions
        • Limit View State Caching
        • Page Level Grouping
      • ASP.NET Output Cache
        • Output Caching Provider Overview
        • Output Cache with Custom Hooks
  • .NET Third Party Integrations
    • Entity Framework (EF) Core
      • Installation
      • Configure
      • EF Core Extension Methods
        • Extension Methods
        • Cache Handle
        • Caching Options
        • Query Deferred API
      • Logging in EF Core
    • Entity Framework EF 6
      • EF Second Level Cache
      • EF Caching Resync Provider
      • EF Caching Configuration File
    • NHibernate
      • Second Level Cache
      • Query Caching
      • Synchronize Database with Cache
    • Debug NCache Providers in Visual Studio
  • Java Third Party Integrations
    • Hibernate
      • Second Level Cache
      • Configure Cacheable Objects and Regions
      • Configure Application
      • Query Caching
    • Spring
      • Overview
      • Use NCache with Spring
        • Configure Generic Provider
        • Configure JCache Spring Caching Provider
        • Configure Caching Declaration
        • Configure Spring Sessions
    • JCache API
      • CRUD Operations
      • Expiration
      • Events
  • Third-Party Wrappers
    • AppFabric to NCache Migration
      • AppFabric API vs. NCache API
      • Configuration Differences Between AppFabric and NCache
      • Migrating from an AppFabric Application to NCache
    • Redis to NCache Migration
      • Redis to NCache Migration
    • Memcached Wrapper
      • Memcached Gateway Approach
      • Memcached Client Plugin for .NET

Cache Management Operations on Cache

The NCache Management API is a set of programmable method calls that enable the user to perform basic management operations on OutProc caches without using either the NCache Management Center or Command Line Tools. This Management API is usually self-sufficient when executing a request.

Prerequisites

  • .NET
  • Java
  • Legacy API
  • 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.
  • For API details, refer to: CacheConnection, CacheManager, CacheConnectionOptions, CacheClientConnectivityChanged, CacheClientConnectivityChangedCallback, ClientInfo, ConnectedClientList, GetCacheHealth, StartCache, StopCache, GetCache.
  • 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.
  • For API details, refer to: CacheConnection, CacheManager, CacheConnectionOptions, onClientConnectivityChanged, ClientInfo, getConnectedClientList, CacheHealth, startCache, stopCache, getCache.
  • Create a new Console Application.
  • Make sure that the data being added is serializable.
  • Add NCache References by locating %NCHOME%\NCache\bin\assembly\4.0 and adding Alachisoft.NCache.Web and Alachisoft.NCache.Runtime as appropriate.
  • Include the Alachisoft.NCache.Web.Management namespace in your application.

Start Cache Using API Calls

The StartCache method enables the user to start an OutProc cache on the specified server.

Start Cache

The cache starts using the StartCache method by using the server IP and cache name. In this example, the user must specify the cache and server IP to start a node.

  • .NET
  • Java
  • Legacy API
// Specify cache name and server info
string cacheName = "demoCache";
string serverIp = "20.200.20.40";

// Provide server info to CacheConnection
var connection = new CacheConnection(serverIp);

// Use CacheConnection to start cache
CacheManager.StartCache(cacheName, connection);
// Initialize cache name and server info
String cacheName = "demoCache";
String serverIp = "20.200.20.40";

// Provide server info to CacheConnection
CacheConnection connection = new CacheConnection(serverIP, port);

// Use CacheConnection to start cache
CacheManager.startCache(cacheName, connection);
System.out.println("Cache started successfully.");
// Precondition: Cache has been registered but not initialized.
string cacheName = "mycache";
string serverName = "...."; // specify the server where cache is registered

CacheManager.StartCache(cacheName, serverName);

Start Cache with Security Enabled

If management level security is enabled, the user needs to provide the user credentials to perform any management operations on the cache. The StartCache method lets you start a cache with user credentials. The following example starts a cache with security enabled on it.

  • .NET
  • Java
// Provide user credentials to CacheConnection
connection.UserCredentials = new Credentials("your-username", "your-password");

// Start cache with the security credentials
CacheManager.StartCache(cacheName, connection);
// Initialize security credentials
String userName = "john_smith";
String password = "12345";

// Initialize cache name and server info
String cacheName = "demoCache";

// Provide user credentials to CacheConnection
Credentials credentials = new Credentials(userName, password);
CacheConnection connection = new CacheConnection(serverIP, port);
connection.setUserCredentials(credentials);

// Start cache with security enabled
CacheManager.startCache(cacheName, connection);
System.out.println("Cache started successfully with security credentials.");

Stop Cache Using API Calls

The StopCache method stops a cache on a particular server. If users don't specify a server, the method reads information from the client configuration file. If called from the client node, the first server listed in the client configuration file associated with the cache stops. You can stop a cache with enabled as well as disabled security. Moreover, the cache may also stop gracefully by setting the gracefullyShutDownNode flag as true.

Stop Cache

This example stops the cache on an already started node. The cache name and server IP to stop on a given node needs to be specified.

  • .NET
  • Java
  • Legacy API
// Use CacheConnection to stop cache
CacheManager.StopCache(cacheName, connection);
// Stop cache
CacheManager.stopCache(cacheName, connection, true);
System.out.println("Cache stopped successfully.");
CacheManager.StopCache(cacheName, serverName);

Stop Cache With Enabled Security

The following example shows how to stop a cache on a particular server with enabled security by providing it with user credentials.

  • .NET
  • Java
// Provide user credentials to CacheConnection
connection.UserCredentials = new Credentials("your-username", "your-password");

// Stop cache with the security credentials
CacheManager.StopCache(cacheName, connection);
// Provide user credentials to CacheConnection
Credentials credentials = new Credentials(userName, password);
connection.setUserCredentials(credentials);

// Stop cache with security credentials
CacheManager.stopCache(cacheName, connection, true);
System.out.println("Cache stopped successfully with security enabled.");

Viewing Cache Status Using API calls

Note

Make sure that you have included the following namespace in your program: Alachisoft.NCache.Runtime.CacheManagement.

The GetCacheHealth method enables users to view the cache server node status. This method call returns a CacheHealth object against every call. You can specify the cache name, the server node, and the management port to get the cache health information. The following example gets the cache-health for the cache demoCache, registered on the server node specified, and listens on port number 9803.

  • .NET
  • Java
  • Legacy API
// Get cache health on the specified node
CacheHealth cacheHealth = CacheManager.GetCacheHealth(cacheName, connection);

Console.WriteLine($"Cache : {cacheHealth.CacheName}\nNode : {serverIp}\nTopology : {cacheHealth.Topology}\nNode Status : {cacheHealth.Status}");
// get cache health of the specified cache
CacheHealth cacheHealth = new CacheHealth();
cacheHealth.setCacheName(cacheName);
CacheStatus status = cacheHealth.getStatus();
CacheHealth cacheHealth = CacheManager.GetCacheHealth(cacheName);

Monitoring Clients Connected to Cache

NCache provides the feature of enabling Client Activity Events. Using these events, each client connects to a clustered cache and can subscribe to notify about the connect/disconnect events of other clients. Each client can also specify a process-level custom identifier that returns to the subscriber based on the client's requirements, it can connect to or disconnect from a clustered cache. Client Activity Events fire when a client connects to or disconnects from a specified cache. These events are registered against the specified cache and are handled in a user-defined callback method.

Connect to Cache

The AppName is a process-level unique identifier that can be assigned at the time of cache connection. For this purpose, before connecting to the cache, create an instance of CacheConnectionOptions and assign a custom identifier string to its AppName property. Thus, if this client connects or disconnects, the callbacks of all the clients who subscribed to the client will get this AppName in their ClientInfo instance.

  • .NET
  • Java
  • Legacy API
// Create an instance of CacheConnectionOptions
var options = new CacheConnectionOptions();

// Assign the custom identifier
options.AppName = "MyApp";

// Connect to cache with custom AppName property
ICache cache = CacheManager.GetCache(cacheName, options);
// Create an instance of CacheConnectionOptions
CacheConnectionOptions options = new CacheConnectionOptions();

// Assign the custom identifier
options.setAppName("MyApp");

// Connect to cache with custom appName property
cache = CacheManager.getCache(cacheName, options);
System.out.println("Cache connected successfully");
string cacheName = "myPartitionedCache";

CacheInitParams initParams = new CacheInitParams();
initParams.AppName = "AssignedAppName"; // assign custom identifier

// initialize cache with custom AppName property
Cache cache = NCache.InitializeCache(cacheName, initParams);

Create Event Callback Method

The callback method is user-defined and is called once the clients are connected/disconnected from the cache. The method is registered against the CacheClientConnectivityChanged event property of the CacheClientConnectivityChangedCallback type in a specific cache. Hence, the method created should match the signature of the delegate:

  • .NET
  • Java
  • Legacy API
public delegate void CacheClientConnectivityChangedCallback(string cacheId, ClientInfo client);

The created method contains the following parameters:

// User defined event callback method
static void MyClientConnectivityCallback(string cacheName, ClientInfo clientInfo)
{
    // Handle event
}
public interface cacheClientConnectivityChangedCallback {
String cacheName = "demoCache";

void invoke(String cacheName, ClientInfo clientInfo);

static void myClientConnectivityStatus(String cacheName, ClientInfo clientInfo)
}
public delegate void CacheClientConnectivityChangedCallback(string cacheId, ClientInfo client, ConnectivityStatus status);

The method created contains the following parameters:

// user defined event callback method
static void MyClientConnectivityCallback(string cacheName, ClientInfo clientInfo, ConnectivityStatus status)
{
    // handle event
}


Parameters Description
cacheName Name of the cache with which the clients are connected or disconnected. This acts as the sender of the event.
clientInfo An object of the ClientInfo class containing information regarding the client which caused the event to fire.

Client Info Class

Member Description
AppName User assigned, process-level, unique identifier.
ClientID Unique ID of client.
IPAddress IP through which the client is connected.
MacAddress Mac address of the client.
PhysicalCores Available physical cores of the client.
LogicalCores Available logical cores of the client.
ProcessID Process ID of the client.
MachineName Machine name of the client.
Status The connectivity status of the cache client.
ClientVersion The version of the cache client.
IsDotNetCore Flag to check whether the client is .NET Core or not.
Memory Available memory of the client.
Operating System The operating system used by the client.

Register Event

The method is registered by appending it to the CacheClientConnectivityChanged property as an event callback. This enables the client to listen for connect/disconnect events of other clients. If another client connects to or disconnects from the specified cache, the callback method is called.

  • .NET
  • Java
  • Legacy API
// Register method to event
cache.MessagingService.CacheClientConnectivityChanged += MyClientConnectivityCallback;
cache.getNotificationService().addCacheConnectivityChangedListener(new CacheClientConnectivityChangedImpl());
// register method to event
cache.CacheClientConnectivityChanged += MyClientConnectivityCallback;

Monitor Client Info of Connected Clients

The ClientInfo of each connected client is available locally in the form of the cache.ClientInfo property.

View List of Connected Clients

To get information on all the clients connected to the cache on demand, use the ConnectedClientList property on the cache as:

  • .NET
  • Java
  • Legacy API
// Connect to cache with custom AppName property
ICache cache = CacheManager.GetCache(cacheName, options);

// Get list of all connected clients
IList<ClientInfo> connectedClients = cache.ConnectedClientList;

Console.WriteLine($"Following are the clients connected to '{cacheName}':");
foreach(ClientInfo clientInfo in connectedClients)
{
    Console.WriteLine($"Client ID : {clientInfo.ClientID}");
}
List<ClientInfo> connectedClients = cache.getConnectedClientList();
    for (var clientInfo : connectedClients){
        System.out.println("Client ID: " + clientInfo.getClientID());
    }
IList<ClientInfo> connectedClients = cache.GetConnectedClientsList();

See Also

Start Cache
Stop Cache

In This Article
  • Prerequisites
  • Start Cache Using API Calls
    • Start Cache
    • Start Cache with Security Enabled
  • Stop Cache Using API Calls
    • Stop Cache
    • Stop Cache With Enabled Security
  • Viewing Cache Status Using API calls
  • Monitoring Clients Connected to Cache
    • Connect to Cache
    • Create Event Callback Method
    • Register Event
    • Monitor Client Info of Connected Clients
    • View List of Connected Clients
  • See Also

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top