Determines whether the cache contains a specific key.
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 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
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.
Or simply in a class deriving from [!:Alachisoft.NCache.Web.UI.NPage] or [!:Alachisoft.NCache.Web.UI.NUserControl].
CopyC#
if(NCache.Cache.Contains("MyTextBox.Value")) { Response.Write("Item found!"); }
CopyC#
if(Cache.Contains("MyTextBox.Value")) { Response.Write("Item found!"); }
Exceptions
Exception | Condition |
---|---|
System..::..ArgumentNullException | key contains a null reference (Nothing in Visual Basic). |
System..::..ArgumentException | key is not serializable. |