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
- Install the following NuGet packages:
- 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.
- For API details, refer to: ICache, Contains, Count, DataTypeManager, Remove, cache.Remove.
- To ensure the operation is fail safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
- To handle any unseen exceptions, refer to the Troubleshooting section.
Tip
One quick way to verify whether datatype has been removed is to use either properties of the Cache class:
Contains
verifies if the specified key of the hashset exists in the cache.Count
returns the number of items present in the cache.
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 = "ProductIDList";
// Remove List from Cache
cache.DataTypeManager.Remove(key);
}
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 ArgumentException or ArgumentNullException
}
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
Using Counter in Cache
Configure Searchable Attributes
Configure Invalidation Attributes
Query on Data Structures