Microsoft AppFabric becoming extinct has impacted the AppFabric customers greatly as Microsoft announces no further development on AppFabric. With the retirement of AppFabric, Microsoft also recommended some alternatives for it that can be used and NCache popped as a recommended alternative by Microsoft. I have a blog written that covers the advantages of migrating your AppFabric application to NCache.
With that being established, the next step is to learn the actual migration from AppFabric to NCache. This blog provides you a step-wise guide on what needs to be done for a seamless migration from AppFabric to NCache.
Migration from AppFabric to NCache
The best part about migrating from AppFabric to NCache is the ease of no code change required for the migration. You just have to edit the references and a few configurations to provide access to the cache along with downloading the NuGet package and your application is good to go. The NuGet package along with the sample application is uploaded on GitHub.
Step 1: Remove References from Project
The first step is to remove the NuGet package
Microsoft.ApplicationServer.Caching.Client or references to the following AppFabric libraries from your application:
Additionally, remove the following namespaces from your application:
Step 2: Download NCache AppFabric Wrapper NuGet
NCache provides a NuGet Package to be installed in your AppFabric application. The NuGet package contains the client.ncconf file that is used to configure the cache client to access NCache cluster from the client machine. The client.ncconf file contains the cache ID of the cache to be used.
Step 3: Add Namespace to the Project
In your project and source files, add the following namespace:
Adding this namespace lets you use NCache’s API for performing all the operations on your cache that NCache’s rich feature set provides. You can see all the major NCache supported features on our website.
Step 4: Configure the appSettings Section
The next step is to configure the appSettings section in your application. The following keys and values need to be modified from the appSettings section of your application’s App.confg file.
- Default: The ID of the default cache that is used. If you do not use a named cache, the application uses the default cache specified here using the GetDefaultCache()
- Expirable: A Boolean value flag that determines weather the cached items need an expiry set on them or not.
- TTL: For Expirable set true, this is the expiration time after which the cached items expire. The default value is 10 minutes and is used in case you have no value specified. The format is hrs:minutes:seconds.
Look at the sample configuration below to see how your appSettings should look like after adding the aforementioned configurations:
<add key="Default" value="myDefaultCache"/>
<add key="Expirable" value="True"/>
<add key="TTL" value="05:30:00"/>
Step 5: Connect to Cache
The next step is to connect to the cache and make sure it is running so operations can be performed seamlessly. You can learn how to create a cache from the step wise guide in NCache documentation. The types of caches and their connection options can be:
- InProc Local Cache: Local server is already available on the local in-process cache so it must be already created and running. Just reference the name of the cache as your cacheName and you can perform operations on your cache.
- OutProc Cache: For an outProc cache, make sure that the cache specified in the ncconf is created and running. Reference the cache as cacheName in your application.
Once your application is connected to the NCache cache cluster, you can perform operations on your cache easily. And that is it, your application is now migrated to NCache. So, following just a few steps migrates your entire AppFabric application to NCache without any hassle.
To sum it up, what we learned from the blog is how NCache wrapper lets you migrate your entire AppFabric application to NCache by following a series of simple steps. You can easily use NCache’s features by just using the NCache AppFabric wrapper with no code change. There are a lot of other features provided by NCache that enhance your application’s performance and help you achieve the scalability you wish for.