Alachisoft NCache 4.1 - Online Documentation

Initialize Cache

 
After you have configured the cache, embed NCache API calls in your application to use it. The first thing you need to do is to initialize the cache. Include the following namespace in your project:
 
using Alachisoft.NCache.Web.Caching;
 
The code for initializing the cache is as follows:
 
// Initialize the cache.
Cache _cache = NCache.InitializeCache("myCache");
 
  Initializing Cache in ASP.NET Applications
 
If you're developing ASP.NET application, the best place to put InitializeCache call is in your Application_Start() functions in Global.asax.cs file. Additionally, instead of hard-coding, we recommend keeping the cache-name in Web.Config and then accessing it from your code. This way, if you will be required to change your cache name at any stage, you won't have to recompile the code.
 
// Pick up the cache-name from Web.Config
public override void Init()
{
string cacheName = ConfigurationSettings.AppSettings["CacheName"];
Cache _cache = NCache.InitializeCache(cacheName);
}
 
And, in your Web.Config, you can specify cache name as follows:
 
<appSettings>
<add key = "CacheName" value = "myCache"/>
</appSettings>
 
 
  See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.