Alachisoft.com

How to Programmatically Initialize a Cache

NCache provides users with the facility to override the default cache initialization settings that are already set in client.ncconf file. CacheInitParams is a class that holds these customized parameters that can be passed to the NCache.InitializeCache API in order to initialize a specific cache. It holds the set of parameters that control the initialization behavior of the cache. Instead of the application picking up certain settings from the config files, you can dynamically give these settings through your code.

The full definition of the object is Alachisoft.NCache.Runtime.Caching.CacheInitParams. Here is a step by step process to use CacheInitParams to add server information of a cache cluster.

Step 1

Add references to the file Alachisoft.NCache.Runtime.Caching which is located at
%install-folder% NCache\bin\assemblies\4.0

Namespace: Alachisoft.NCache.Web.Caching
Assembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll)

Step 2

Initialize the object as follows:

CacheInitParams param = new CacheInitParams();
Step 3

Add Server information by creating CacheServerInfo object and add server information to it as follows:

CacheServerInfo[] info = new CacheServerInfo[2];
info[0] = new CacheServerInfo("20.200.20.102",9800);
info[1] = new CacheServerInfo("20.200.20.101",9800);

Then add the CacheServerInfo object to the CacheInitParam

param.ServerList  = info;
Step 4

Add the CacheInitParams to the InitializeCache API call

Cache _nCache = NCache.InitializeCache("mycache", param);

Find the complete list of CachiInitParams Members at Alachisoft website.

What to Do Next?