Migrating from an AppFabric Application to NCache
To migrate from 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.
If you do not have NCache installed on your client machine, you can use the client.ncconf file added to your application project when you install the NCache AppFabric wrapper NuGet package to configure the cache client to access the NCache cluster. If you have NCache on your machine, 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 to use. This property 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. If you do not want to set an expiry on your cached items, then set this flag to False.
<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 not affect the cached items if the
Expirabletag is 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 ensure the cache is created and running.
If you use a local in-process cache as configured in the config.ncconf file, then that local server is already available to you, created, and running. You need to reference that cache as your
cacheName. If you use an in-process local cache, ensure that the cache (with the ID provided in client.ncconf with the cache server configurations) is created and running. This cache must be mentioned as
cacheNamein your application. To create and start a cache, refer to our documentation on Configure Caches.
Ensure the client.ncconf file has its cacheName set for you to configure a 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.
NCache provides an AppFabric wrapper application and sample application on GitHub.