Replacing AppFabric With NCache

Introduction
 

What is AppFabric?

Microsoft's AppFabric for Windows Server is middleware consisting of two main features, AppFabric Hosting deploy and manage Windows Workflow Foundation (WF), workflows that are hosted in Windows Communication Foundation (WCF) services. Additionally, it contains an extension for IIS that allows performance and workflow monitoring along with PowerShell commands to manage persistence, hosting, and monitoring tasks.

AppFabric caching, the second main feature, is an in-memory, distributed cache that runs on one or more on-premises servers to provide a performance and scalability boost for .NET Framework applications.

AppFabric caches stored data in key-value pairs using the physical memory across multiple servers.

AppFabric Lifecycle

AppFabric uses Microsoft's fixed lifecycle policy, which indicates that mainstream support for AppFabric 1.1 ended on April 11, 2017. Extended support lasts until April 12, 2022. Microsoft has added one additional note:

AppFabric 1.1 for Windows Server support ends on the date indicated unless distributed as a component of SharePoint Server 2013, 2016, and 2019. Components receive the same support as their parent product or platform.

To replace AppFabric, Microsoft has created a migration guide, detailing which products Microsoft recommends using. This primarily includes the usage of NCache or Redis Cache services. Please click here to read more about it. 

What is NCache?

NCache is an Open Source in-memory distributed cache for .NET, Java, and Node.js. NCache is extremely fast and linearly scalable and caches application data to reduce expensive database trips. Use NCache to remove performance bottlenecks related to your data storage and databases and scale your .NET, Java, and Node.js applications to extreme transaction processing (XTP).

In this article, I’m going to explain how to Use NCache as AppFabric alternative. 

Install NCache Manager

Download NCache from NCache Download Center (alachisoft.com). I highly recommend you to install the Enterprises edition so that you can explore all the features. Before the installation make sure .NET 6 has been installed in your machine. 

After completing the download and installation process, you can run the NCache Web Manger in the bowser from localhost 8251 port, as shown in the below figure.

We can create a clustered and local caches from the NCache Manager application.

For this demo, I have created a local cache and named it “myLocalCache” using Ncache Manager as shown in the below figure.

Click here to check how to create a local Cache using NCahce Web Manager.

Let’s do the stress test to check our cache status. Run below command in command prompt to start the stress test 

"test-stress <Cache Name>"

Now the stress test has been completed, check the count from cache statistics. You can go to Cache statistics by selecting our cache from NCache Web Manager and clicking on the statistics icon. 

 

How to Use NCache as AppFabric alternative? 

There are some specific reasons why NCache is used as a better alternative for AppFabric. Because it is 100% native .NET and runs on windows platform, the oldest and more stable .NET distributed cache with fully supported official .NET and Java Clients and is much more powerful. 

We have two options to migrate AppFabric to NCache 

  1. Using AppFabric wrapper 
  2. Making Direct NCache API Calls 

Using AppFabric wrapper

No code changes are required while using AppFabric wrapper, just by installing the wrapper package and replacing the Namespace will do the job to go. 

Making Direct NCache API Calls

It requires code changes but no logic changes are required and it's more powerful with NCache features.

Note: We can use AppFabric Wrapper and NCache API’s can be used side by side. 

Using AppFabric Wrapper 

Just follow three simple steps to migrate from AppFabric to NCache

  1. Download and Add NCache SDK package from Nuget Package Manager
  2. Download and Add NCache Wrapper Nuget Package 
  3. Replace AppFabric Namespace with NCahce Wrapper 

1. Add NCache Nuget Package

Open your existing AppFabric project in your visual studio and Install Alachisoft.NCache.SDK package from NuGet package manager. 

2. Download NCache Wrapper for AppFabric 

Install AppFabric.Wrapper.NCache NuGet in your application. After installing the Nuget package in your AppFabric application, client.ncconf and config.ncconf files will be included in your project.

3. Replace AppFabric Namespace with NCache Wrapper 

Make the following changes in your application .csproj and .cs files.

Remove the references to the following AppFabric libraries,

  • Microsoft.ApplicationServer.Caching

Replace the following namespaces with Alachisoft.NCache.Data.Caching in the using statements of your source files,

  • Microsoft.ApplicationServer.Caching
  • Microsoft.ApplicationServer.Caching.Client
  • Microsoft.ApplicationServer.Caching.Core

After completing all the steps, you can use other extension methods from NCache library. 

Now you should be able to run your AppFabric application using NCache as the distributed caching solution. 

For reference please check this project source from GitHub

Summary

We saw what is NCache, how it can be a better alternative for AppFabric and how it is very to migrate the AppFabric app to NCache as the distributed caching solution. We will see more about NCache in my future articles 

Happy Coding!!!