How to Migrate from AppFabric to NCache

Today we are going to talk about how to migrate your existing applications from AppFabric to NCache. This is a quick how-to video so I'm also going to demonstrate all the options that NCache provides in this case, so let's quickly get started with this.

AppFabric End of Life issues

Now, first of all let's talk about the AppFabric end-of-life issues. Now, we already know that Microsoft has discontinued AppFabric since April (2022) last year so, this means that there is no more official support for this product, no more bug fixes, any security platform or compatibility updates, any improvements or enhancements in this product. Apart from that AppFabric is not open source, so there is no active online community to back it up. So, you cannot use any online help in order to resolve any kind of issue.

So, this makes AppFabric a very risky product to use in a production environment because first of all it's an obsolete product, it's not supported. And, the third and the most important reason is that the cost of failure is extremely high. So, migration from AppFabric needs to happen on a highest priority, and Microsoft itself recommends this.

Use NCache for Migration

So, what are the options in this case? The best and the most recommended option is to use NCache for migration. Now the reason for this is that NCache is a 100% .NET native distributed caching solution that runs on a Windows platform. It is very feature-rich, extremely stable, and gives you, very easy options to replace AppFabric in your applications with NCache. Apart from that NCache is a fully supported product where you get timely releases, timely security, and compatibility updates. And, let's say, if you face any kind of issue we work very closely with our customers, and with you guys to actually resolve that issue as well.

So, NCache is a .NET native product, runs on a Windows platform, very feature rich, gives you very easy options to replace AppFabric, and then the most important reason is that NCache is a fully supported product.

Migration Options

Now, let's talk about the options that NCache provides in order for you to migrate off of the AppFabric. So, there are two migration options.

  1. NCache AppFabric Wrapper Approach

    The first one is the NCache AppFabric wrapper approach. Now, this is a no-code change, and the most easiest option where you don't need to change anything within your application, and then you keep using AppFabric APIs which then call NCache APIs behind the scenes, and it is very seamless for your application. The complete wrapper code is open source and it is also available on our GitHub page.

    • No-Code change option
    • Keep using AppFabric APIs
    • Wrapper code is Open Source
  2. NCache Direct APIs Approach

    The second option, or the second approach is the NCache direct APIs approach. In this approach you would have to change some code within your application, but let me tell you it is very straightforward, extremely easy to implement, and it gives you more control and flexibility. It also enables you to use the extended features of NCache that AppFabric completely lacks because it's a very limited product.

    • Code change (Minimal)
    • Easy to implement
    • More developer control
    • Use extended features of NCache
 

NCache AppFabric Wrapper Approach

So, let's talk about the NCache AppFabric wrapper approach. Now, we have certain, steps that you guys use that we, suggest in order to replace AppFabric with NCache using this approach. So, I'm going to demonstrate all these steps here in this in this video as well.

  1. Remove AppFabric Assembly References

    So, let's start off with the step number one which is removing the AppFabric assembly reference. Now, I have an AppFabric sample application as you can see here, so I'm just going to go ahead and comment out the assembly reference of AppFabric here.

  2. Install NCache Wrapper NuGet Package

    Let's go to the second step, and which is installing the NCache wrapper NuGet package. So, let's go to the NuGet package manager here, NuGet packages, and let's go to browse, and type "appfabric ncache", there we go. So, it will show you the NCache AppFabric Enterprise, Professional and Open Source NuGet packages. I'm going to focus on the Enterprise NuGet package. I've already installed it in my project here as you can see it right here. And, once you install it you also get to, it will also deploy the NCache assemblies. So, all these assemblies are also deployed in my project. So, let's go back now.

  3. Include NCache Wrapper Assembly Reference

    Now, let's go to the third step which is including the NCache wrapper assembly reference. So, it's a very simple step. Let's go to the top and press Enter, and I'm simply going to type 'using Alachisoft.NCache.Data.Caching', there we go. So, that's it, perfect.

  4. Specify NCache Configurations inside Application

    Now, let's go to the fourth step which is specifying the NCache configurations inside your application. So, all you have to do is just go to the App.Config file inside the app settings section as you can see here there are certain cache configurations. So, first of all let's focus on the CacheId which is the name of the cache where this application will connect to. In our case we have the 'appfabricncachetest'. Then, we have some expiration tags here as well. So, by default expiration is set to true, and the expiration time is 15 minutes by default. You can also change it as per your own requirement as well.

Let's go back, and before we run the application let me quickly tell you how this works. So, first of all we're using the DataCacheFactory to initiate the cache connection, as you can see it's the, AppFabric API. So, if you go to the PrepareClient(), let's go inside this method, as you can see it's getting the cache name and then it's calling the DataCacheFactory.GetetCache method here. So, this this will initiate the connection to the cache for your application, let's go back. After that, it will run some, test in the application. So, let's go inside this one. So, since this is a quick how-to video I'm going to focus on the CRUD operations. Let's go inside any one of the methods here, let's go into the first one, and select the first one here as well. So, here you can see we're using the Add method API which is the DataCache.Add() API of AppFabric. Now, if I go inside the DataCache you can see, these are all the AppFabric APIs that we have implemented in the NCache AppFabric wrapper, that your application will use. So, basically your application will call these APIs, and behind the scenes these APIs will resolve into NCache APIs, and NCache will be used behind the scenes, and your application will not notice any difference in this case. So, let's go back, and let's go back again, and again.

Now, I have already configured the NCache environment in my end. As you can see I have 'AppFabricNCacheTest' cache hosted on two nodes here yes, and I've also opened, by the way, just to let we have another video published on our website which you can use to configure NCache in your environment, install it, create cache and stuff like that. So, you can use that as a reference as well.

NCache Manager

I've also opened the, monitor for this cache as you can see. And, for the report view, I've also opened the statistics view of this cache as well. Let's go back, and go to the project again, and let's run this application, there we go. Let's open this one, and there we go, perfect.

//using Microsoft.ApplicationServer.Caching;
using Alachisoft.NCache.Data.Caching;
using System;
using System.Configuration;

namespace NCacheAppFabricConsoleUI
{ 
    class Program
    {
        static DataCacheFactory myCacheFactory; 
        internal static string myObjectForCaching = "This is my Object";
        internal static DataCache myDefaultCache;
        static void Main(string[] args)
        {
            try
            {
                PrepareClient();
                RunSampleTest();
            }
            catch (Exception exp)
            { 
                Console.WriteLine(exp.ToString());
            }

            Console.ReadLine();
        }
	...

So, now we can see the application has finished this, execution. We are seeing some output in the command prompt here, and if I go back, you can see in the NCache web monitor we have one client connected to both nodes. Some requests coming in. Count is increased.

NCache Monitor

If I go to statistics you can see client is connected to both nodes, and there's some count on this cache which means that there are some item present in the cache now. There we go.

NCache Statistics

Now, there's one more comment that I wanted to add. Let me quickly go back, there we go. So, all these, messages that you are seeing here, specifically the, exceptions, now these are the exact same messages or the exact same exception type that you would receive from AppFabric.

So, we're keeping the exact same experience in the wrapper approach so you won't notice any difference between AppFabric and NCache while using this, this specific approach here.

Now another thing that I wanted to show you guys here. So, let me quickly close this one, and go back to the website, there we go. So, all these steps that we have performed, these are already published on our website in the documentation. So, you can even use this documentation as a reference to, follow the NCache AppFabric wrapper approach. And, the same sample application along with the wrapper code. We have also, as I mentioned it is open source, so it is also available on our GitHub page as well as you can see right here. So, you can also download this sample along with the wrapper code and then, test it on your end, review it, and see how this works.

 

NCache Direct APIs Approach

So, guys this was all in regards to the NCache AppFabric wrapper approach, now let's talk about the NCache direct APIs approach. Now I have, another sample here.

//using Microsoft.ApplicationServer.Caching;
using System;
using System.Configuration;
using Alachisoft.NCache.Client;

namespace NCacheAppFabricConsoleUI
{
    class Program
    {
        internal static ICache cache;
        static DataCacheFactory myCacheFactory;
        internal static string myObjectForCaching = "This is my Object";
        internal static DataCache myDefaultCache;
        static void Main(string[] args)
        {
            try
            {
                PrepareClient();
                RunSampleTest();
            }
            catch (Exception exp)
            {

                Console.WriteLine(exp.ToString());
            }

            Console.ReadLine();
        }
	...

It's just the same sample application, let me bring it up, there we go. Now in this application, instead of using the Data.Caching assembly of NCache we're going to use the Alachisoft.NCache.Client assembly. So, in order for you to use that you have to install the NCache NuGet package. So, let's go to the NuGet package manager. Go to browse and type NCache, there we go. So Alachisoft.NCache.SDK. This is the Enterprise NuGet package that you would need to install in your application. I've already installed it here, so as you can see here I have the Alachisoft.NCache.SDK installed. Again this will deploy all the NCache assemblies in your application.

Let's go back. Now, in order for you to, see the difference, now instead of using data cache factory, we're using the ICache interface of NCache Client assembly. This is to use, in order to create a connection between your client and the application. So, let's go to the PrepareClient(); now, and if you can see now we're getting the cache name, and we are simply using the CacheManager.GetCache(cacheName); which is the ICache, method here. This will initiate the cache connection for your application. Let's go back, and after that, we'll run some sample tests again. So, we'll open the exact same method here as well, there we go, and there we go. Now previously we were using the myDefaultCache.Add but now we're going to use the cache.Add method of NCache existing direct API. You can see ICache.Add.

So, as you can see there's nothing much of a difference between these two APIs here. So, these are very similar to each other as well. So, let's go ahead, and let me actually go back, and try to run the application now. Go back again, and let's run the application. Here we go and let's open the monitor again. Perfect. So, you can see the application has finished its execution. It's able to, perform all the operations as you can see here.

If I go back you can see the clients are connected to both nodes again, some requests coming in, the count increased as well.

NCache Monitor

So, if I go to statistics view you can see again the count is increased to 8 here as well. So, this is how simple it is as well.

NCache Statistics

If I go back to the application, and let me bring another comment here as well. So, you can see, there was a very slight difference between the NCache API as well as the, AppFabric API, and that's the reason why I mentioned that it's a very little code change in your application. You don't have to make massive changes within the application because APIs are very similar to each other as well. Let's say, if you want to still review the NCache APIs and AppFabric APIs differences we have a page available for that as well, as you can see here AppFabric API vs. NCache API. This will list down all the APIs of AppFabric and their, alternative NCache APIs as well for all the operations.

Next Steps

Download NCache Free 30-Day Trial

So guys, this was all in regards to the NCache direct APIs approach. Now what are the next steps here? First of all, I would highly, encourage you guys to download the NCache free 30-Day trial version where you get a fully working product in trial, which you can use for your own testing purpose purposes. In order for you to do that you can simply go to our website, and that is the alachisoft.com and if you go and hit click on the download button on the top here it will open the NCache Download Center.

So, for .NET Edition you can see we have certain installers here. So, you can install any version of NCache for either on Windows or Linux in order for you to, use NCache instead of AppFabric.

Try NCache Playground

Secondly, I would also, suggest that you try the NCache Playground here. Now, this will give you a pre-configured sandbox session where you would have a 2-node cluster, and in this cluster you would be able to edit and run .NET and Java sample samples here. So, this will not require you to do any sort of, pre-installation, any configuration on your end. This is available on our website and once you install NCache on your machine you also get this as part of the NCache installation. And, in order for you to try that you can simply go to our website again and on each page on the top right you could see the Try Playground button as you can see here. If we click on it, this will open the NCache Playground, and this is the sandbox session here.

We have another video where we have, provided all the details on how to use the NCache Playground. So, I would, strongly recommend that you go ahead and view that video and then see how you can play around with NCache Playground feature.

Schedule a Personalized NCache Demo

Finally I would also suggest that you schedule a personalized NCache demo because this way you get to learn about the complete NCache Architecture, all the features of NCache, and how they can benefit your use case, and how you can use NCache in your environment. So, it's a very good, opportunity for you to do that as well. And, in order for you to do that you can simply again go to our website and schedule a personalized demo by filling up this form here.

So guys, this was all in regards to the AppFabric migration to NCache, all the steps, all the options that we discussed in this video. If you still have any more questions just feel free to reach out, and I thank you so much for your time, and I hope you have a good day.

What to Do Next?

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