Initializes the instance of Cache for this application.

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

Syntax

C#
[ObsoleteAttribute("This method is deprecated. 'Please use InitializeCache(string cacheId, CacheInitParams initParams)'", 
	false)]
public static Cache InitializeCache(
	string cacheId,
	string server,
	int port,
	bool balanceNodes,
	SecurityParams primaryUserCredentials,
	SecurityParams secondaryUserCredentials
)
Visual Basic
<ObsoleteAttribute("This method is deprecated. 'Please use InitializeCache(string cacheId, CacheInitParams initParams)'", 
	false)> 
Public Shared Function InitializeCache ( 
	cacheId As String,
	server As String,
	port As Integer,
	balanceNodes As Boolean,
	primaryUserCredentials As SecurityParams,
	secondaryUserCredentials As SecurityParams
) As Cache
Visual C++
public:
[ObsoleteAttribute(L"This method is deprecated. 'Please use InitializeCache(string cacheId, CacheInitParams initParams)'", 
	false)]
static Cache^ InitializeCache(
	String^ cacheId, 
	String^ server, 
	int port, 
	bool balanceNodes, 
	SecurityParams^ primaryUserCredentials, 
	SecurityParams^ secondaryUserCredentials
)

Parameters

cacheId
Type: System..::..String
The identifier for the Cache item to initialize.
server
Type: System..::..String
The identifier for the server where the cache is running.
port
Type: System..::..Int32
The port at which the server accepts the remote client connections.
balanceNodes
Type: System..::..Boolean
True to select the least loaded server, false to connect to the given server anyway
primaryUserCredentials
Type: Alachisoft.NCache.Web.Security..::..SecurityParams
Holds the primary user-id and password used for authorization if security is enabled.
secondaryUserCredentials
Type: Alachisoft.NCache.Web.Security..::..SecurityParams
Holds the secondary user-id and password used for authorization if security is enabled. These credentials are used incase primary credentials are not athorized.

Return Value

Type: 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.

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.

Examples

This sample shows how to use the InitializeCache(String) method inside a sample Web application.
 Copy imageCopy
public override void Init()
{
    // A cache with id 'myCache' is already registered.
    try
    {
        Alachisoft.NCache.Web.Caching.Cache theCache = NCache.InitializeCache("server-name", "myServer","9900", new Alachisoft.NCache.Web.Security.SecurityParams("domain\\user-id","password")));
    }
    catch(Exception e)
    {
        // Cache is not available.
    }
}

Exceptions

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

See Also