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:
Remove the
Microsoft.ApplicationServer.Caching.Client
NuGet package or references to the following AppFabric libraries from your application's source code:- Microsoft.ApplicationServer.Caching.Client.dll
- Microsoft.ApplicationServer.Caching.Core.dll
Remove the following namespaces from your project:
Microsoft.ApplicationServer.Caching
Microsoft.ApplicationServer.Caching.Client
Microsoft.ApplicationServer.Caching.Core
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.
Add the
Alachisoft.NCache.Data.Caching
namespace 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"/>
Default
is 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"/>
Expirable
is 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 toFalse
.<add key="TTL" value="hh:mm:ss"/>
TTL
is 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>
Note
- The
TTL
will have no effect if theExpirable
tag is set to False. - If the
Expirable
is set to True and noTTL
is 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.
Note
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.
Additional Resources
NCache provides AppFabric wrapper application and sample application on GitHub.
See Also
Configuration Differences Between AppFabric and NCache
.NET API Reference for NCache