Remove Existing Data Structure from Cache
Note
This feature is only available in NCache Enterprise Edition.
An existing datatype can be removed from cache using the Remove method of DataTypeManager or through cache.Remove method as well. If the key does not exist, nothing is returned.
Pre-requisites
- Include the following namespaces in your application:
Alachisoft.NCache.Client.DataTypes
Alachisoft.NCache.Client
Alachisoft.NCache.Runtime.Exceptions
- The application must be connected to cache before performing the operation.
- Cache must be running.
- To ensure the operation is fail safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
Tip
One quick way to verify whether datatype has been removed is to use either properties of the Cache class:
The following example assumes the key exists against a data type in cache.
try
{
// Pre-condition: Cache is connected
// Key exists in cache
string key = "ProductIDSet";
// Remove HashSet from Cache
cache.DataTypeManager.Remove(key);
// OR
//cache.Remove(key);
// Verify datatype removal through cache.Contains() or cache.Count
}
catch (OperationFailedException ex)
{
// NCache specific exception
// Exception can occur due to:
// Connection Failures
// Operation Timeout
// Operation performed during state transfer
}
catch (Exception ex)
{
// Any generic exception like ArgumentNullException or ArgumentException
}
Recommendation: To ensure the operation is fail safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
See Also
List Behavior and Usage in Cache
Queue Behavior and Usage in Cache
Sets Behavior and Usage in Cache
Dictionary Behavior and Usage in Cache
Using Counter in Cache
Configure Searchable Attributes
Configure Invalidation Attributes
Query on Data Structures