Initializes the instance of Cache for this application.

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


public static Cache InitializeCache(
	string cacheId,
	CacheInitParams initParams
Visual Basic
Public Shared Function InitializeCache ( _
	cacheId As String, _
	initParams As CacheInitParams _
) As Cache
Visual C++
static Cache^ InitializeCache(
	String^ cacheId, 
	CacheInitParams^ initParams


Type: System..::..String
The identifier for the Cache item to initialize.
Type: Alachisoft.NCache.Web.Caching..::..CacheInitParams
Holds the initialization parameters for Cache.


The cacheId parameter represents the registration/config id of the cache.

Calling this method twice with the same cacheId increments the reference count of the cache. The number of InitializeCache(String) calls must be balanced by a corresponding same number of Dispose()()()() calls.

Multiple cache instances can be inititalized within the same application domain. If multiple cache instances are initialized, Cache refers to the first instance of the cache.

Note: When starting a Cache as outproc, this method attempts to start NCache service on the local machine if it is not already running. However it does not start the cache automatically.


This sample shows how to use the InitializeCache(String) method inside a sample Web application.
public override void Init()
    // A cache with id 'myCache' is already registered.
        CacheInitParams initParams = new CacheInitParams();
        initParams.BalanceNodes = true;
        initParams.ConnectionRetries = 5;
        initParams.Mode = CacheMode.OutProc;
        initParams.MultiPartitionConnection = false;
        initParams.OperationTimeout = 30;
        initParams.Port = 9900;
        initParams.PrimaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password");
        initParams.RetryInterval = 5;
        initParams.SecondaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password");
        initParams.Server = "server";
        Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myCache", initParams);
    catch(Exception e)
        // Cache is not available.


System..::..ArgumentNullExceptioncacheId is a null reference (Nothing in Visual Basic).

See Also