Migrating AppFabric Application to NCache
To migrate your AppFabric application to NCache, follow these steps:
Make the following changes in your application's source code:
Microsoft.ApplicationServer.Caching.ClientNuGet package or references to the following AppFabric libraries from your application's source code:
Remove the following namespaces from your project:
Download the NCache AppFabric Wrapper NuGet package in your application.
In case you do not have NCache installed on your client machine, then you can use the client.ncconf file that is added to your application project when you install the NCache AppFabric wrapper NuGet package to configure the cache client to access NCache cluster. If you have NCache installed on your machine, then you can find this file at %NCHOME%\config.
Alachisoft.NCache.Data.Cachingnamespace in your project.
After you have installed the NuGet package and edited the namespaces, you need to configure the appSettings section of your App.config. Add the following keys and values to the appSettings:
<add key="Default" value="name-of-the-default-cache-here"/>
Defaultis the ID of the default cache that will be used. This is required if your application is calling the default cache.
<add key="Expirable" value="True"/>
Expirableis a Boolean value flag that determines whether the cached objects should have an expiry set on them or not. If you do not want to set expiry on your cached items, then set this flag to
<add key="TTL" value="hh:mm:ss"/>
TTLis the expiration time set on cached items.
An example of what your appSettings should look like is shown below.
<appSettings> <add key="Default" value="myDefaultCache"/> <add key="Expirable" value="True"/> <add key="TTL" value="05:30:00"/> </appSettings>
TTLwill have no effect if the
Expirabletag is set to False.
- If the
Expirableis set to True and no
TTLis given, then the default expiration time of 10 min will be used on all cached items.
- Next you need to make sure that the cache is created and running.
If you are using a local in-process cache as configured in the config.ncconf file, then that local server is already available to you, created and running. What you need to do is reference that cache as your cacheName.
In case you are not using an in-process local cache, then make sure that the cache with the ID provided in client.ncconf with the cache server configurations is created and running. This created cache needs to be referenced as cacheName in your application.
To create and start a cache, refer to our documentation on Configure Caches.
Make sure that the client.ncconf file has entry of the set cacheName for you to be able to configure cache client that can access the cache.
These steps will allow you to connect your AppFabric application to the NCache cache and execute object caching CRUD operations on it.
NCache provides AppFabric wrapper application and sample application on GitHub.