Method InitializeCache
InitializeCache(String)
Initializes the instance of Cache for this application.
Declaration
public static Cache InitializeCache(string cacheId)
Parameters
Type | Name | Description |
---|---|---|
System.String | cacheId | The identifier for the Cache item to initialize. |
Returns
Type | Description |
---|---|
Cache |
Remarks
The cacheId
parameter represents the registration/config id of the cache.
Depending upon the configuration the Cache object is
created inproc or outproc.
As this overload does not take Alachisoft.NCache.Web.Security.SecurityParams, internally it tries to load this information from "client.ncconf" file. For more details see NCache Help Collection.
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 Alachisoft.NCache.Web.Caching.Cache.Dispose(System.Boolean) calls.
Multiple cache instances can be inititalized within the same application domain. If multiple cache instances are initialized, Alachisoft.NCache.Web.Caching.NCache.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.
Examples
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.
try
{
Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myCache");
}
catch(Exception e)
{
// Cache is not available.
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
InitializeCache(String, CacheInitParams)
Initializes the instance of Cache for this application.
Declaration
public static Cache InitializeCache(string cacheId, CacheInitParams initParams)
Parameters
Type | Name | Description |
---|---|---|
System.String | cacheId | The identifier for the Cache item to initialize. |
CacheInitParams | initParams | Holds the initialization parameters for Cache. |
Returns
Type | Description |
---|---|
Cache |
Remarks
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 Alachisoft.NCache.Web.Caching.Cache.Dispose(System.Boolean) calls.
Multiple cache instances can be inititalized within the same application domain. If multiple cache instances are initialized, Alachisoft.NCache.Web.Caching.NCache.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.
Examples
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.
try
{
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.
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
InitializeCache(String, String)
Initializes the instance of Cache for this application. Initializes client cache that keeps synchronized with remote cache.
Declaration
public static Cache InitializeCache(string remoteCacheId, string clientCacheId)
Parameters
Type | Name | Description |
---|---|---|
System.String | remoteCacheId | Level 2 cache id |
System.String | clientCacheId | Level 1 cache id |
Returns
Type | Description |
---|---|
Cache | Cache instance |
Remarks
The remoteCacheId
parameter represents the registration/config id of the cache.
The Cache object can only be created as outproc. An exception
will be thrown otherwise.
The clientCacheId
parameter represents the registration/config id of the cache.
Depending upon the configuration the Cache object is
created inproc or outproc.
Examples
This sample shows how to use the InitializeCache(String) method inside a sample Web application.
public override void Init()
{
// A remote cache with id 'myReplicatedCache' and client cache with id 'myCache' is already registered.
try
{
Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("myReplicatedCache","myCache");
}
catch(Exception e)
{
// Cache is not available.
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentNullException |
|
InitializeCache(String, CacheInitParams, String, CacheInitParams)
Initializes the instance of Cache for this application.
Declaration
public static Cache InitializeCache(string remoteCacheId, CacheInitParams remoteInitParams, string clientCacheId, CacheInitParams clientInitParams)
Parameters
Type | Name | Description |
---|---|---|
System.String | remoteCacheId | The identifier for the remote Cache item to initialize. |
CacheInitParams | remoteInitParams | Holds the initialization parameters for the remote Cache. |
System.String | clientCacheId | The identifier for the client Cache item to initialize. |
CacheInitParams | clientInitParams | Holds the initialization parameters for the client Cache. |
Returns
Type | Description |
---|---|
Cache |
Remarks
The remoteCacheId
parameter represents the registration/config id of the cache.
Calling this method twice with the same remoteCacheId
increments the reference count
of the cache. The number of InitializeCache(String) calls must be balanced by a corresponding
same number of Alachisoft.NCache.Web.Caching.Cache.Dispose(System.Boolean) calls.
Multiple cache instances can be inititalized within the same application domain. If multiple cache instances are initialized, Alachisoft.NCache.Web.Caching.NCache.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.
Examples
This sample shows how to use the InitializeCache(String) method inside a sample Web application.
public override void Init()
{
// A cache with id 'remoteCacheId' and 'clientCacheId' is already registered.
try
{
CacheInitParams remoteInitParams = new CacheInitParams();
remoteInitParams.BalanceNodes = true;
remoteInitParams.ConnectionRetries = 5;
remoteInitParams.Mode = CacheMode.OutProc;
remoteInitParams.MultiPartitionConnection = false;
remoteInitParams.OperationTimeout = 30;
remoteInitParams.Port = 9900;
remoteInitParams.PrimaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password");
remoteInitParams.RetryInterval = 5;
remoteInitParams.SecondaryUserCredentials = new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id", "password");
remoteInitParams.Server = "remoteserver";
CacheInitParams clientInitParams = new CacheInitParams();
clientInitParams.Mode = CacheMode.InProc;
Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("remoteCache", remoteInitParams, "clientCache", clientInitParams);
}
catch(Exception e)
{
// Cache is not available.
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|