Initializes the instance of Cache for this application.
Namespace: Alachisoft.NCache.Web.CachingAssembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.0.0)
Syntax
C# |
---|
public static Cache InitializeCache( string remoteCacheId, CacheInitParams remoteInitParams, string clientCacheId, CacheInitParams clientInitParams ) |
Visual Basic |
---|
Public Shared Function InitializeCache ( _ remoteCacheId As String, _ remoteInitParams As CacheInitParams, _ clientCacheId As String, _ clientInitParams As CacheInitParams _ ) As Cache |
Visual C++ |
---|
public: static Cache^ InitializeCache( String^ remoteCacheId, CacheInitParams^ remoteInitParams, String^ clientCacheId, CacheInitParams^ clientInitParams ) |
Parameters
- remoteCacheId
- Type: System..::..String
The identifier for the remote Cache item to initialize.
- remoteInitParams
- Type: Alachisoft.NCache.Web.Caching..::..CacheInitParams
Holds the initialization parameters for the remote Cache.
- clientCacheId
- Type: System..::..String
The identifier for the client Cache item to initialize.
- clientInitParams
- Type: Alachisoft.NCache.Web.Caching..::..CacheInitParams
Holds the initialization parameters for the client 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 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.
Examples
This sample shows how to use the InitializeCache(String) method inside a sample Web application.
CopyC#
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
Exception | Condition |
---|---|
System..::..ArgumentNullException | remoteCacheId is a null reference (Nothing in Visual Basic). |