Remove Existing Data Structure From Cache
You can remove an existing data structure from the cache using the Remove
method of DataTypeManager
or through the cache.Remove
method as well. If the key does not exist, nothing is returned.
Prerequisites
- To learn about the standard prerequisites required to work with all NCache client-side features please refer to the given page on Client Side API Prerequisites.
- For API details, refer to: ICache, DataTypeManager, Contains, Count, Remove.
Remove Data Structures from Cache
Tip
One quick way to verify whether the data structure has been removed is to use either property of the Cache
class:
Contains
verifies if the specified key exists in the cache.Count
returns the number of items present in the cache.
The following example assumes the key exists against a data structure in the cache. The data structure is then removed from the cache using this key.
// Precondition: Cache is connected
// Key exists in cache
string key = "ProductIDList";
// Remove List from Cache
cache.DataTypeManager.Remove(key);
Note
To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.
Additional Resources
NCache provides a sample application for removing data structures from cache on GitHub.
See Also
.NET: Alachisoft.NCache.Runtime.Caching namespace.
Java: com.alachisoft.ncache.runtime.caching namespace.
Node.js: NamedTagsDictionary class.
Python: ncache.runtime.caching class.