Determines whether the cache contains a specific key.

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#
public override bool Contains(
	string key
)
Visual Basic
Public Overrides Function Contains ( 
	key As String
) As Boolean
Visual C++
public:
virtual bool Contains(
	String^ key
) override

Parameters

key
Type: System..::..String
The key to locate in the Cache.

Return Value

Type: Boolean
true if the Cache contains an element with the specified key; otherwise, false.

Remarks

In most of the cases this method's implementation is close to O(1).

Note: In a partitioned cluster this operation is an expensive one as it might result in network calls. It is therefore advised to use this property only when required.

Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.

Examples

The following example demonstrates how to check for containment of an item in the Cache.
 Copy imageCopy
if(NCache.Cache.Contains("MyTextBox.Value"))
{
    Response.Write("Item found!");
}
Or simply in a class deriving from [!:Alachisoft.NCache.Web.UI.NPage] or [!:Alachisoft.NCache.Web.UI.NUserControl].
 Copy imageCopy
if(Cache.Contains("MyTextBox.Value"))
{
    Response.Write("Item found!");
}

Exceptions

ExceptionCondition
System..::..ArgumentNullExceptionkey contains a null reference (Nothing in Visual Basic).
System..::..ArgumentExceptionkey is not serializable.

See Also