• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

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
  • Install the Alachisoft.NCache.SDK NuGet package.
  • Include the following namespaces in your application:
    • Alachisoft.NCache.Client
    • Alachisoft.NCache.Runtime.Exceptions
  • For API details, refer to: CacheManager, CacheConnectionOptions, CacheClientConnectivityChangedCallback, ClientInfo, ConnectedClientList, GetCache.
  • Add the following Maven dependencies in your pom.xml file:

    <dependency>
          <groupId>com.alachisoft.ncache</groupId>
          <artifactId>ncache-client</artifactId>
          <version>x.x.x</version>
    </dependency>
    
  • Import the following packages in your application:
    • import com.alachisoft.ncache.client.*;
    • import com.alachisoft.ncache.runtime.exceptions.*;
    • import com.alachisoft.ncache.runtime.cachemanagement.*;
  • For API details, refer to: CacheConnection, CacheManager, CacheConnectionOptions, onClientConnectivityChanged, ClientInfo, getConnectedClientList, getCache.
  • Create a new Console Application.
  • Install the following NuGet package in your .NET client application:
    • Enterprise: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • 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.Managementand Alachisoft.NCache.Runtime.CacheManagement namespaces in your application.
  • To utilize the APIs, include the following in your application:
    • Alachisoft.NCache.Web.dll
    • Alachisoft.NCache.Runtime.dll
  • To learn more about the NCache Legacy API, please download the NCache 4.9 documents available as a .zip file on the Alachisoft Website.

Monitoring Clients Connected to Cache

NCache allows you to enable Client Activity Events, which notify clients about the connection and disconnection of other clients in a clustered cache. Each client can also define a custom process-level identifier, which is shared with subscribers when the client connects to or disconnects from the cache. Client Activity Events fire when a client connects to or disconnects from a specified cache. These events are registered for a specific cache and are handled through user-defined callback methods.

Note

Make sure that client events have been enabled through NCache Manager before proceeding to use them.

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 cache = CacheManager.getCache(cacheName, options);
// Using NCache Enterprise 4.9.1

// Create an instance of CacheInitParams
CacheInitParams initParams = new CacheInitParams();

// Assign custom identifier
initParams.AppName = "MyApp";

// Connect to 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);

    // User defined event callback method
    static void myClientConnectivityStatus(String cacheName, ClientInfo clientInfo)
    {
        // Handle event
    }
}
// Using NCache Enterprise 4.9.1
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
cache.MessagingService.CacheClientConnectivityChanged += MyClientConnectivityCallback;
cache.getNotificationService().addCacheConnectivityChangedListener(new CacheClientConnectivityChangedImpl(callback));
// Using NCache Enterprise 4.9.1
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;

foreach(ClientInfo clientInfo in connectedClients)
{
    Console.WriteLine($"Client ID : {clientInfo.ClientID}");
}
// Connect to the cache
Cache cache = CacheManager.getCache(cacheName);

// Get list of all connected clients
List<ClientInfo> connectedClients = cache.getConnectedClientList();

for (var clientInfo : connectedClients)
{
    System.out.println("Client ID: " + clientInfo.getClientID());
}
// Using NCache Enterprise 4.9.1

// Connect to cache
string cacheName = "myPartitionedCache";
Cache cache = NCache.InitializeCache(cacheName);

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

foreach (ClientInfo clientInfo in connectedClients)
{
    Console.WriteLine("Client ID : " + clientInfo.ClientID);
}

See Also

Start Cache
Stop Cache

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • 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 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top