NCache - Five Steps to Getting Started

This short video explains in five steps how to set up and use NCache. NCache is an Open Source in Memory Distributed Cache for .NET. It improves your application performance and scalability. So, the five steps are:

  1. NCache Software Setup
  2. Create Cache Cluster
  3. Configure Cache Clients
  4. Test Cache Cluster
  5. Use Cache in Application

NCache Software Setup

So, let's start with the first step of NCache software setup. If your application is running in an on-premises situation, then you need to download NCache from our website. If you come to our website, you can go to the download page. I strongly recommend that you download NCache Enterprise Edition, because it has all the features that you might find useful, even if you end up using the open source edition later on.


  • Download NCache
  • Enterprise Edition
  • Install Cache Server
  • on all cache servers
  • Setup Cache Client
  • install .msi or use NuGet

Azure Marketplace

  • Cache Server VM
  • From marketplace
  • Setup Cache Client
  • install .msi or use NuGet

AWS Marketplace

  • Cache Server VM
  • From marketplace
  • Setup Cache Client
  • install .msi or use NuGet

If your application is running in one of the cloud platforms, then NCache is available in the Azure and AWS Marketplace. There's a pre-configured cache server VM that you can purchase from there. So, for example if you come to Azure you'll see that in the Azure marketplace NCache Enterprise is available and the same goes with the AWS Marketplace. You'll see that NCache enterprise is available in both of these marketplaces. For any other cloud, you just need to download NCache from our website and install it. NCache runs on all the cloud platforms even if it may not be available in the marketplace.

The client portion of NCache you can install either through a Windows Installer, or if you can use a NuGet package then you can come to our NuGet site and you'll see that there are a bunch of NuGet packages. For all of the API calling you use the NCache.SDK. For the session services for ASP.NET Core you use this NuGet package, for session state provider for ASP.NET you'd use this package.

The hardware that is required to run NCache servers is typically an 8 to 16 core CPU server, although you can take the number of cores higher if you have a larger transaction load. And then the typical RAM configuration is 16 to 32 Gig. But again, as I said, you can increase the RAM based on your needs and you need at least of 1 to 10 gigabit network card. NCache runs on both Windows Server and Linux and again I'm talking about the both the cache server and the client.


  • CPU (8-40 cores)
  • As needed
  • RAM (16-128 GB)
  • Add more servers if needed
  • NIC (1-10 Gbit)
  • Clients & Servers both

Windows Server

  • 2019, 2016, 2012 R2
  • .NET 4.7.2, .NET Core 2.2+
  • Cache Server & Client
  • Use of both or either

Linux Server

  • Debian, Fedora, CentOS,
  • Ubuntu, OpenSUSE
  • .NET 4.7.2, .NET Core 2.2+
  • Cache Server & Client
  • Use of both or either

On Windows, NCache can run either as .NET or .NET Core, on either Windows 2019, 2016 or 2012 R2. And of course on Linux, NCache can run only in the .NET Core configuration. You can also combine Windows server based cache servers with clients that are either on Windows or Linux and vice versa. But the cache servers themselves should be ideally on the same operating system.

NCache Deployment in Enterprise

Before I get started, let me quickly tell you how NCache is normally deployed in an enterprise. You would build a cache cluster of minimum of two cache servers. This is a TCP-based cache cluster but you can add more servers as you need. The minimum of two is for redundancy purposes and then after that you maintain a 4:1 or a 5:1 between the application tier and the caching tier.

NCache Architecure

That's based on our best practices and to get the maximum performance from your application. NCache pools the resources of all these cache servers into one logical capacity and if you add a third or fourth server then obviously your capacity increases.

Caching Topology (Linear Scalability)

NCache has multiple caching topologies but I'm going to use the partition replicas topology, because it's the most popular topology. It provides you linear scalability because of partitioning and also a reliability of data through replication. In this topology, every partition is backed up onto a different server, so if any one server goes down you don't lose any data.

Partitioned-Replica Cache

Create Cache Cluster (Watch video from 4:12 – 5:29)

So, let's go ahead and create a cache cluster. I have a bunch of machines here. I'm going to actually use a two server cluster initially. So, let me go ahead here and go to the NCache program group and I will run this NCache web manager. It's a web-based management tool of NCache.

  • And, I'm going to go ahead and create a new cache. So, I will say create and I'm going to name, all caches are named in NCache. I will name my cache demoCache and I can choose either binary or JSON serialization. I'm going to use JSON, what that means is, all of the objects that you store in NCache are going to be stored as in JSON format.
  • I will pick partition replicas as the caching topology, as we talked about.
  • Then I'm going to just take the defaults of asynchronous replication.
  • I will pick my first cache server which is right here. I'm going to specify the second cache server also here. I will go ahead and hit ‘Next’.
  • As you can see, it's very straightforward. You can just in one place, create the entire cache cluster.
Create Cache Cluster

Configure Cache Clients (Watch video from 5:34 – 6:10)

Ok, now that I've created the cache cluster, my next step is to configure the cache clients. So, I'm going to go here. I'll go to the details of this cache cluster. I will come to the, I'll say, add a client node. So my clients are two of them, one is this computer that I'm logged into, which is what it's showing up here. So I'm going to add that and the second client is a Linux box. So as I said I could mix and match Windows and Linux clients. So if your application is running on Linux you can also use that the same cache from that application. So I've also now configured the cache clients.

Configure Cache Clients

Test Cache Cluster (Watch video from 6:13 – 10:44)

Now let's go to this next step, which is test the whole thing, test the cache cluster and make sure that the clients are able to talk to the cache. So, I'm going to come here and I will highlight this and I'll say start the cache.

So once the cache is started, I can then start monitoring it and I will also start to run a test application. I have this, NCache comes with this tool called stress test tool. It's a PowerShell Cmdlet, so I'm going to say monitor first, so as you can see I have got this dashboard style that I can monitor, I can also monitor it in a report style. I'm going to go ahead and start a PowerShell command prompt here and I will run this program called stress test. Now we'll give it a cache name. This is the same cache name that I created right here as you can see, right here. So I'm going to hit Enter and this program now connects to this cluster and you'll see it'll start to appear here, right here.

Test Cache Cluster

So I've got the .82 which is this machine, it's a Windows machine. I've got that client talking to the cache cluster. I can see it here also that the cache activity has just started. I've got one client connected, so this client talks to both of the cache servers and I can see all of that.

So now I'm going to go ahead and I have a Linux machine that I'm logged into, as you can see, so I'm going to do PowerShell here and after I've started the PowerShell. In case of Linux I have to import this module. I will just copy this, I'll paste it here. Now that I've imported the NCache module in PowerShell, I will go ahead and say run that same program here. So it's going to also now start to talk to this cache cluster. So now I have two clients, as you can see here two clients that are talking to the cache cluster both of them are talking to all the cache servers. I can see it here also. Their activity has gone up and I've got two clients here. I can also see the client side counters in terms of the activities and I can see it also here.

So, this is how you would normally use NCache. It's that straightforward but now let's assume that now you're adding more and more stress on your cache servers and the two cache servers are starting to max out. Although it's not happening right here but let's assume that's the case. So I want to show you how you can add a third cache server at run time. So again everything is running, both the clients are still running, I'm going to come here and I will get the IP address of the third cache server, which is right here, and I'm going to say add another server node. I will add this server node here and it just added a third server to the cluster but this has not been started yet so I'm going to come here and I will say start this third server also.

Once this server starts, you'll see that it's going to start to show activity here. So it’s right here, it's going to start to show activity right here. So see now it’s got three servers, 102, 121 and 122. And again the clients are continuing to run without any interruption, even though you just added a third node. You could do the same by just dropping a node and it's going to work fine the same way. In fact, let me just quickly do that. I'm going to come here and I'm saying I don't need the third node anymore, I will just come here and say stop. So if I do stop, you'll see that this is going to drop the third node but everything is going to continue working as if nothing happened.

And that's the high availability part of NCache that you can do that at run time you can scale it up or down, by adding more servers or dropping servers from the, as you can see it's still stopping there it is, so that server is gone. And as you can see, the applications continue to work. So that should give you a pretty good idea of how to test, to make sure the cache cluster is working.

Use Cache in Application (Common Uses of NCache)

The 5th step is to use the cache in your application. And there are four different ways that you can use the cache in your application.

App Data Caching

  • Data exists in BOTH cache & database

ASP.NET / ASP.NET Core Caching

  • ASP.NET Core: Sessions, Response Caching, SignalR
  • ASP.NET: Sessions, View State, Output Cache, SignalR

Pub/Sub Messaging & Events

  • Pub/Sub Messaging, Continuous Query (CQ) & Events

Full Text Searching (Distributed Lucene)

  • In-memory distributed store for Lucene Index & Docs
  • Use standard Lucene API for Full Text Search
  1. Application Data Caching (Watch video from 11:24 - 12:22)

    Number one and the most common is, to do application data caching. This is where you cache or application data. For example, you cache data that resides in the database, it's now cache it here, so you don't have to go to the database as frequently. Idea is about 80% to 90% of the time you should be able to get that data from the cache, so that really reduces the pressure on your database and the application starts to perform super-fast.

    So that's the first one, and let me quickly show you what a typical API looks like. I'm just going to do the basic operations, here I've already shown you the NuGet packages, so when you want to connect to the cache, you connect to the cache in the same in a very simple fashion, you say NCache.Client.CacheManager and GetCache and you give it a cache name. This cache name is that same cache. In our case it's called demo cache that gives you a cache handle.

    So once you get the cache handle then you could do all the cache operations. Let's say, I want to find an object from the cache, I've got a key, which is a string, I just say _cache.Get and I do a key. If that object exists in the cache it'll give me that object or else it's going to give me a null. The same way I can add or insert objects into the cache. I can, so for example here I'm adding an object but I'm also specifying a 1-minute interval for expiration. So this object is going to be expire after one minute. So very straightforward of this example.

  2. ASP.NET / ASP.NET Core Caching (Watch video from 12:55 - 13:36)

    The second use case is if you got an ASP.NET or ASP.NET Core application, you can start to cache your sessions. In case of ASP.NET Core you can start to cache sessions, you can use NCache as the response caching middleware, you can use NCache as the SignalR Backplane especially if your application is running in a multi-server environment. In case of an ASP.NET application you can cache your sessions, viewstate, output cache and again use NCache as a SignalR Backplane.

    Let me show you what an ASP.NET Core application looks like, right here I've got an ASP.NET Core application. Again, in the Startup.cs all you got to do is come here and in to configure services and make this call. And again this sample is available for you and in this call actually, then you're specifying this NCache settings which is in part of the appsettings.json you've got this NCache settings here so that's all you do here. And then in the ‘Configure’ method you say app.Use.NCacheSession(); So this is NCache’s own implementation of the session provider for ASP.NET Core that you've just started to use. Very straightforward.

  3. Pub/Sub Messaging and Events (Watch video from 14:09 - 14:44)

    The third use case is if you've got Pub/Sub messaging and events. So in case of Pub/Sub messaging and events, let me quickly show you NCache becomes like a messaging platform, a messaging bus where your applications are able to use it to communicate to each other.

    Pub/Sub Messaging

    Pub/Sub is a specific type of messaging where you've got multiple publishers and multiple subscribers and they can communicate to each other, send messages in a decoupled fashion and NCache facilitates that in in a very seamless fashion.

    So let me quickly show you what NCache Pub/Sub messaging looks like. Here you've got that same cache handle and you ask the messaging service from the cache handle to get you a topic. A topic is a by name and then based on that topic you just publish a message right here, see _topic.Publish.

    On the other side the subscriber will be subscribing to this topic and when this message goes to that topic the subscribers callback gets called and again these two publisher and subscriber could be on different boxes and they won't even know which boxes this thing came from. So that's a very powerful use. And Pub/Sub messaging, because it's all in-memory superfast much faster than the traditional Pub/Sub messaging platforms that you have and also its native .NET obviously.

  4. Full-Text Searching (Distributed Lucene) (Watch video from 15:28 - 16:07)

    The fourth common use case is full-text Searching. NCache has implemented Lucene API in a distributed fashion, so if you have a .NET or .NET Core application that wants to call Lucene to do full-text searching but you also want to make sure that the Lucene index is very scalable.

    For example if you see this picture here (below) you can see they build the actual Lucene index in a scalable fashion and because NCache is all in memory it's also super-fast. So your application will be standard Lucene application.

    NCache Architecure

    Let me give you an idea what that application looks like. For example, I've got a Lucene application here, so for example, I will go to this and here's the only NCache specific code that you have is when you're setting up the Lucene providers. So you specify NCache as the Lucene directory instead of the file system, everything else stays the same and when you come back to this, you'll see that you can build index and you can execute queries. This is all standard Lucene code, again Lucene .NET code that is now working against NCache.

So those are the four use cases of using NCache that you have please contact our tech support team and schedule a live demo of NCache or watch other videos available on our website. Thank you very much.

What to Do Next?

Signup for monthly email newsletter to get latest updates.

© Copyright Alachisoft 2002 - . All rights reserved.