Method Contains
Contains(String)
Determines whether the cache contains a specific key.
Declaration
public virtual bool Contains(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to locate in the Cache. |
Returns
Type | Description |
---|---|
System.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 in case of failure.
Examples
The following example demonstrates how to check for containment of an item in the Cache.
Cache cache = NCache.InitializeCache("myCache");
if(cache.Contains("MyTextBox.Value"))
{
Response.Write("Item found!");
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|