Getting Started with .NET Edition

Today, I'm going to talk about getting started with the .NET Edition of NCache. There's a separate video on getting started with the Java Edition of NCache if you're interested please do watch that. So, let's get started. There are five steps to getting started with NCache.

  1. Software Setup: This is where you install the NCache servers and the clients.
  2. Create NCache Cluster: NCache creates a TCP-based cluster of NCache servers.
  3. Configure the NCache Clients: These are your application servers or your web servers that you configured them to talk to NCache.
  4. Test the NCache Cluster: To make sure everything is working, the cluster is working, and your clients are able to talk to the cluster.
  5. Use NCache in your Application

Since, this is a .NET Edition video I'm going to talk about the .NET apps. Please note that you can develop the Java, Node.js, and Python applications with NCache as well.


1. Software Setup

Okay, so, the first step is the software setup. Please note that NCache has a server component and a client component. NCache gives you different deployment options.

Deployment Options

NCache Server

  1. On-Premises
    • Download NCache Software
    • Docker "Pull" (NCache Software)
  2. Cloud
    • NCache Cloud (SaaS) (Azure / AWS)
    • NCache Software (BYOL)
    • (Azure / AWS / Google / All Clouds)
  3. Docker / Kubernetes
    • (On-Premises, Cloud)
    • Azure AKS, AWS EKS, Google GKE, Red Hat OpenShift

NCache Clients

  1. .NET
    • NuGet, .NET 4.0+
  2. Java
    • Maven, Java 11+
  3. Node.js
    • npm
  4. Python
    • PyPi


So, if you're planning to deploy NCache in an on-premises situation, in your own data center, you can come to our website to download the NCache software. Just come to our website and go to the download page. Go ahead, and download the .NET Edition. NCache Enterprise either for Windows, .NET 6 for Windows, or .NET 6 for Linux. The Windows is a .msi Windows installer. And, for Linux it's a .tar.gz. Or if you have a legacy .NET 4.8 environment you can also download the .NET 4.8 Windows installer of NCache.

And, then you can also get the NCache clients from here. For the NCache clients portions, if you go to the NuGet tab of this page it gives you a lot more detail. There's the basic Alachisoft.NCache.SDK which everybody needs to get, and then there are a lot of other NuGet packages that NCache offers you. If you go to the and type NCache you'll get a list of all of these as well. So, the downloading of NCache software is the first, or if you if you prefer Docker then you can also do a docker pull. So, if you go to the Docker / Kubernetes tab you'll see that you can do a docker pull alachisoft/ncache:latest and that gets you the .NET edition of NCache on either Windows or Linux, based on your operating system on which you're making this call from.


So, number two is if you are trying to use NCache in the Cloud there are two ways to do it, one is that NCache Cloud SaaS offering which is available on Azure and AWS marketplaces. Let me show you. So, if I were to go to the Azure Marketplace you'll see the NCache Enterprise Cloud that is available. On the same lines, on the same footings, if you go to the AWS Marketplace you'll see the NCache Enterprise Cloud SaaS offering there as well. So, you can actually choose to purchase these when you purchase these you pay Azure or AWS for it and not Alachisoft. But, what I would recommend even if you wanted to go with the SaaS option is to first download the NCache software and do your evaluation or your proof of concept through it, either in an on-premises environment or in the cloud, and then decide whether you want to go with SaaS or purchase NCache software from us. You can purchase software from us and still deploy in the clouds in a BYOL manner. And, if you do that then it is available on all clouds including Azure, AWS, and Google. But, if you go with SaaS then it is only available in Azure and AWS as of today. And, then maybe in future, we'll have other Cloud marketplaces.

Docker / Kubernetes

I've already shown you the Docker option. NCache also supports Kubernetes. So, you can deploy NCache in Azure AKS, AWS EKS, Google GKE, or Red Hat OpenShift Kubernetes environments, wherever you have them.

NCache clients

I've already shown you the NuGet Packages for the .NET client. The same way for Java, you have Maven, for Node.js npm, and for Python you have PyPi that you can use.

System Requirements

The next thing that you need to know is the systems requirement for the NCache server and the client. The NCache server, we offer six different server profiles that you should choose from. There's the SO-4, SO-8, SO-16, SO-32, SO-64, and SO-128. These signify the RAM but then they have corresponding vCPUs. So, for example, I would recommend that in production you should not go anything smaller or weaker than SO-16 which is a 16 Gig RAM with an 8 vCPUs CPU. But, in non-prod, in QA, and testing, you can even go with smaller environments, or smaller boxes if that's what your preference is. Obviously if your transaction load is higher, then you should go with even more than SO-16. So, all those options are available. If you come to our website, and go to the pricing page you'll see all of these options are discussed here for both NCache Enterprise and Professional.

NCache Server

  1. Hardware
    • SO-4 (4GB, 2 vCPUs)
    • SO-8 (8GB, 4 vCPUs)
    • SO-16 (16GB, 8 vCPUs)
    • SO-32 (32GB, 12 vCPUs)
    • SO-64 (64GB, 16 vCPUs)
    • SO-128 (128+GB, 32+ vCPUs)
  2. Windows
    • Windows Server 2022, 2019, 2016
    • .NET 6
  3. Linux
    • Ubuntu, Debian, RHEL
    • .NET 6

NCache Clients

  1. Hardware
    • CPU (8-40 cores), RAM (16-128 GB)
    • Network Card (1-10 Gbit)
  2. Windows
    • Windows Server 2022, 2019, 2016
    • .NET 6 or .NET 4.0+
    • Optional: Java 11+
  3. Linux
    • Ubuntu, Debian, RHEL
    • .NET 6+
    • Optional: Java 11+

The next thing from Hardware is the operating system. So, for .NET developers Windows is the preferred platform, but you have the option of deploying NCache either on Windows or Linux. On Windows we officially support all the latest versions of Windows server. So, for example, as of today you can deploy NCache on Windows server 2022, 2019, and 2016. On Linux you can deploy NCache on Ubuntu, Debian, and Red Hat Enterprise Linux. Please note that on either of these two platforms you need to have .NET 6 installed because it's a .NET Edition, so there's a server side .NET code that it needs to be able to run, especially if you do like read-through, write-through, and other server-side code.

The client-side Hardware is very similar to the server-side hardware because NCache clients are actually application servers and Web servers. So, these are also server platforms. So, go with the similar type of profile hardware, and again you have the option of going with Windows or Linux, as I said, our experience is that the .NET developers prefer to use Windows as their main operating systems. If you also have the same preference please note the NCache fully supports Windows in an official capacity the same way Windows 2022, 19, or 16. And, then either .NET 6 or .NET 4.0+ depending on what your application is using. And then, if you have Java then obviously Java 11+.

The same thing is on Linux. You can deploy your applications on Linux that can talk to NCache on either Ubuntu, Debian, or Red Hat Enterprise Linux. But here, if you have a .NET application deploying on Linux then you obviously have to have .NET 6 or later version, but if you have a Java application then you can have Java 11 or later.

Distributed Cache for Mission Critical Apps

NCache has two different ways that is used. Either it's a distributed cache in mission critical applications, or is there a Messaging and Streams platform. There's more detail about that in the NCache Architecture video please do watch that.

Distributed Cache for Mission Critical Apps

But, in either case NCache is deployed as a cluster of two or more servers. In a distributed cache, you know, we recommend like a 5:1 between your application servers and the cache servers. You can go slightly higher ratio as well but we recommend that you stay closer to it to get the optimum performance, because the whole reason you're using NCache is to improve your performance and scalability.


2. Create NCache Cluster

Now, let's go ahead and create an NCache Cluster. I will come to this one box, and actually even before I do that I'm going to … so, I have three servers that I have, they're available to me. All of them are Windows server boxes, and two clients. One client is a Windows server box and the other client is a Linux box. So, I'm going to show you a two server Cluster first, and then I'll add a third server at runtime. So, I will go to NCache and go to the management center. This is a very powerful tool from NCache. Currently, it is looking at the local box. I am currently at this box but I need to actually go ahead and manage this box. I'm going to change the IP address from localhost to this, and I'll hit Enter. Now I'm talking to that server. So, I'm going to go ahead and create a Distributed Cache. I'll call my cache ‘democache’. I will use JSON as my serialization instead of binary.

Create NCache Cluster

You can read more about it on our docs. JSON obviously is more for platform and language neutrality and portability.

I'm going to use Partition Replica Cache as the topology and an asynchronous replication.

Partition Replica Cache

Again, all of that is explained in a lot of detail in the NCache Architecture video, so, please do watch that. I will pick one Gig as my cache size. Yours is obviously going to be a lot more than this. Our average customer, as I said, has a 16 Gig profile in production. So, I'm going to add my first server is 109. Then my next server here is 110. So, I'm going to specify both of them at this time. Add Node.

Set Cache Partitions and Size

So, I'm going to start with a two node cache cluster. I will keep everything else as default. I'm not going to ‘Enable Compression’ but I do want to let you know that this is a very powerful feature.

Encryption and Compression Settings

So, if you have object sizes larger than a certain threshold it will start to compress them and that improves your overall throughput and scalability of your application.

I'm going to keep my Eviction on, and I will choose the least recently used as my algorithm or policy, and I will evict 5% of the cache. This eviction kicks in when the cache is full. So, I had specified one Gig as the partition size. So, if that partition gets full that it will evict 5%. I can also turn this off in which case it will not do any eviction but then if the cache is full it will start rejecting any new data. So, in most cases, you want to keep it on.

Enable Eviction

So, I'm going to keep the 15sec Clean Interval, that's the interval at which NCache doses its own cleanup, bookkeeping, a lot of other, you know, important work, like explorations, and stuff are done in this time. I'm going to say ‘Start this cache on finish’. I you should probably also turn this on ‘Auto start this cache on service startup’ but I'm not going to do that.


3. Configure Clients

Now, I have created the cache, the next I'm going to do is configure the clients. It's still creating it, while it is, I'm going to add only one client at this time and then I will add the second client at runtime while the application is running and the cache is also running, okay. So, I've got this cache already started. I'm going to say ‘Monitor’ the cache, I will also do ‘Statistics’, and these are two different views. Let me just go ahead and make sure my … let me minimize this, so that you can see … Sorry about that. So, I'm going to come here and now you can see that this is a complete dashboard.

NCache Management Center

4. Test the NCache Cluster

Again you can see there are no clients running. So, I'm going to just quickly test to make sure that this cluster is working. I'm going to just run a 'Stress Test' test. So, on 109 server itself, a stress test tool is run and then becomes a client even though it's on the same server as the cache, but it's still a client. It is just going to put some stress for about 30 seconds. It's doing almost 3,000 operations per second combined between the two nodes.

Test the NCache Cluster

Now that I have that much done, my next goal is to add a client. So, I'm going to go ahead and add this as my client and again I am logged into this box and let me show you the proof of it, I would say ‘ipconfig’ and you can see it is 112. So, I'm going to come here, and this is probably stopped already, I'm going to come here and go into the ‘View Details’ and I will come here and say ‘Add’ a client node and I will do 112. I will add 112.

Add a Client at Runtime

Now that I've added 112 you'll see that I'm not seeing the clients here as because I haven't run anything yet. I've only added the client node to the configuration. So, now I'm going to come here and I'm going to use the Powershell commandlet called Test-Stress. Really very useful and powerful commandlet tool that we give you with NCache. I'm going to run it. As soon as I run it you'll see that my client becomes one, because now I have an application that is talking to the cache and suddenly it has put load. So, it's doing about 3,000 per box, you know, close to 6,000 requests per second is what it's doing to the whole cluster with just one client.

Stress Test Stats

The cache is running, the application is running. Although right now this two node cluster is not maxed out nowhere near, but let's assume that it was, and you wanted to add a third server. So, I'm going to go ahead and add a third server at runtime, and by add at runtime means when everything else is running nothing stops while I'm going to add a third server. So, I'm going to come here to the server nodes and I will say ‘Add’ and the third server was 111, so, I'm going to say 111. I will say ‘Add’. It just added that to the configuration but that server hasn't started. So, I'm going to click it here and say ‘Start’. Before I do that you can see that an empty third server has been added to the configuration but it hasn't been started. I'm going to hit the ‘Start’ button and you'll see that suddenly it'll come to life, and when it does then it's going to start to take over some of the load.

So, now that same 6,000 that was there previously to two nodes now it's distributed to three nodes. Obviously until I add more client activity more transactions are not going to be added but I'm just showing you that if two servers were being, you know, full or being maxed out that you could add a third server at runtime, and suddenly the load shifts at runtime without causing any data loss.

Add a Server at Runtime

Now that I've added a server at runtime I'm going to also add another client at runtime. This is another client machine. So, you may want to also increase your … in fact, that's more likely to happen than the server because until you reach that 5:1 or something like that ratio you probably don't need to add an additional server, but I'm going to come here, and again everything is running, so, I'm going to come to the client's node and I will say 113, that's the box, right? 113. I'm going to add that, and that is a Linux box, but you'll see that it doesn't show it here because I haven't run any applications on it yet. So, I'm going to come here. I'm actually logged into that 113 box you can see. It's a Linux box. So, I'm going to run a stress test tool from Linux just to add more stress to this, and actually let me just come here, so that you can see that currently I have only one client, and I'm going to run the other client. As soon as I do this number is going to go up to two right there, see. It went up to two and suddenly the request per second load coming from three, and this is all on three servers, it has increased by almost 50% on each of those.

Add Client at Runtime

So, now if I were to see the ‘Report View’ I've got about 3500 per server average which is what about 10,500 or something like that. This is all approximation of course because that keeps fluctuating.

Report View

Now I have shown you how to add a server at runtime, I've shown you how to add a client at runtime, I'm going to, on the same client box, add another application process. So, I am going to take the Windows box and I've got another PowerShell command prompt here I'm going to run another client. This stress test tool is really powerful it really lets you see a lot of activity very quickly. Now you can see more activity just kicked in. Because, even though the number of client machines are only two but on one machine I've got one application, on one I've got two. So, I've got a total of three clients.

Run another Client at Runtime

Let's go ahead and add another client process, or another application from the Linux box also. So, I've got another separate login for the Linux, I've got one here, and one here, and just to again show you this is same, it's also the same 113 box. So, I'm going to come here and I will again add another box I've got now four clients. So, now two clients per client machine and my load keeps on going.

Run another Client at Runtime on Linux Box

So, that's a really good demonstration of how you can do everything at runtime and how easy it is. You can do everything from a central management center, this is both management and monitoring that really makes your life very easy. Okay, let me now get back, and I'll enable my video.


5. Use NCache in your Application

Distributed Cache

So, I've actually now tested the cluster also, and then now the final step is to use NCache in your application. Since this is a .NET Edition video I'm going to focus more on .NET applications, even though you can do Java, Node.js, and Python applications as well. So, as I had already mentioned there are two common uses of NCache, one is to use it as a distributed cache the second to use it as a messaging and stream. Here's what the diagram look like.

Distributed Cache for Mission Critical Apps

Here's what a distributed cache looks like where the NCache sits in between your application tier and your database. And, the goal is to cache as much of the data from the database, so your application doesn't have to go to the database. At least 80% of the time it gets its data from NCache, and your application performance improves, it's also becomes very scalable. So, that's the first use case.

Messaging and Streams Platform

The second use case is use NCache as a Messaging and Streams platform. It's again a super-fast and scalable platform of two or more servers. Here you have multiple decoupled applications.

NCache as a Messaging and Streams Platform

These could be Web Apps, Microservices, Web APIs, or any other server applications. These could be .NET, Java, Node.js, and Python, talking to each other through Pub Sub Messaging. They could also use Continuous Query, and there's also other Event features in NCache. So, those are the two major use cases of NCache.

Sample Code

So, let me show you some sample code for the App Data Caching .NET where it is going to use NCache API. But, before I show you that code let me show you that you can actually come to GitHub, and there's an NCache samples, a repository that has .NET, .NET Core, Java, Node.js samples. We're adding the Python samples. So, I've downloaded all of these samples on my computer. So, I've got them right here. So, I can come into the .NET Core sample. And, I have three of these samples open, that one, Pub/Sub sample and the Session Caching sample. So, I'm going to show you each of these.

So, the basic operation sample is to show you the app data caching with the NCache API. So, I'm going to go here and go into basic operations it's a very straightforward console application, it connects to NCache first. It does an ‘NCache.client.CacheManager.GetCache’, specifies a cache name. This cache name is ‘democache’ which is what we had specified here, which is right here, that's the cache that we had created here, right here. Whatever you name it that's the cache. And, once it gets the cache handle then you can see that you can do ‘_cache.Add, _cache.Get, _cache.Insert’. Insert means add if it doesn't exist otherwise update. And, then ‘_cache.Remove’. They are obviously a lot more than this but this is just to give you a quick overview of what the basic operations samples look like.

The next sample is to look at the ASP.NET Core Session Caching. So, this is an ASP.NET Core application, as you can see here. I have minimized my video. So, I'm going to go into ‘Startup.cs’. In the configure services you can just need to do an ‘services.AddNCacheSession’ and then Configure Section, and then it has a ‘NCacheSettings’, and then if you were to go to ‘appsettings.json’ you'll see NCache settings has again that same NCache name specifies as ‘democache’ in our case. And, the second thing they have to do is in the configure method you have to do app.UseNCacheSession(); and this is our NCache’s own implementation of Session Storage for ASP.NET Core which has a lot of additional features than standard session caching or storage. So, that's also very powerful. So, that's all you need to use to start to use NCache for the session storage. So, I've shown you the App Data Caching. I've shown you the Sessions ASP.NET Core. Obviously there's more to it than this.

Let's quickly see Pub/Sub Messaging. So, I'm going to come here and open the distributed … let me minimize my video here. You can see that I've got a publisher and a subscriber. These are the two separate applications. Here's the Run() method of the publisher. In this sample it just creates three threads. I'm going just going to go to the RunPublisher thread. It does RunPublisher, RunBulkPublisher, RunAsyncPublisher. I'm just going to show you it connects to the cache the same way that I had shown you right here. Again the same way it gets the cache handle, then it publishes messages. I'm sorry, RunPublisher publishes messages. So, I'm going to go ahead and publish message. Publish message essentially gets a topic handle based on a topic name and just keeps publishing messages. So, publisher publishes message in a decoupled fashion, and there are different publishers publishing.

And, now you have a subscriber which is a separate application supposedly. And, it also connects to the cache the same way, and it just creates a subscription. I'm just going to come here RunSubscriber. So, subscriber essentially again gets a cache handle the same way, and then it creates a topic, and then it creates a subscription on it. A subscription basically means that a subscriber says I am interested in this topic if there are any messages published by publishers please call my call back. So, then the call back is called, and the call back can then take action against whatever that message is.

So, very decoupled very powerful way of using NCache in a Pub / Sub messaging. So, that that's a sort of a good overview of what NCache is all. I would say go and download the samples from GitHub repository. And, please go ahead and download 60-day trial of NCache. As I've already mentioned NCache has a free 60-day trial that can be extended for up to six months total.

NCache Playground

And, there's another feature of NCache which is called Playground which is a fully working of NCache copy live on our website that you can quickly access through just a browser. So, you don't have to do any installation, any setup, none of that. Just start to play with some of these samples and you can even run these samples. You can even look at the EF Core sample and run it. There's a separate video about this. I'm not going to go into the details of this but it's a very powerful concept that helps you very quickly start to get a feel of what NCache is capable of.

Thank you very much for your time. We look forward to having you play with NCache and start using it in your applications. Thank you very much.

What to Do Next?

Signup for monthly email newsletter to get latest updates.

© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.