• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Remove Existing Data Structure from Cache

Note

This feature is only available in the NCache Enterprise Edition.

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

  • .NET/.NET Core
  • Java
  • Scala
  • Node.js
  • Python
  • 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.
  • 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: Cache, getDataStructuresManager, contains, getCount, remove.
  • 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: Cache, get_count, DataStructuresManager, getDataStructuresManager.
  • 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: Cache, getDataStructuresManager, contains, getCount, remove.
  • 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: Cache, DatastructureManager, contains, getCount, remove.

Remove Data Structures from Cache

Tip

One quick way to verify whether the data structure has been removed is to use either properties 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.

  • .NET/.NET Core
  • Java
  • Scala
  • Node.js
  • Python
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
}
try {
    // Pre-condition: Cache is connected

    // Key exists in cache
    String key = "ProductIDList";

    // Remove List from Cache
    cache.getDataStructuresManager().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 IllegalArgumentException or NullPointerException
}
try {
    // Pre-condition: Cache is connected
    // Key exists in cache
    val key = "ProductIDList"

    // Remove List from Cache
    cache.getDataStructuresManager.remove(key)
}
catch {
    case exception: Exception => {
      // Handle any errors
    }
}
// This is an async method
try {
  // Pre-condition: Cache is connected

  // Key exists in cache
  var key = "ProductIDList";

  // Remove List from Cache
  await this.cache.getDataStructuresManager().remove(key);
} catch (error) {
  // Handle errors
}
try:
    # Pre-condition: Cache is connected
    # Key exists in cache
    key = "ProductIDList"

    # Remove List from Cache
    cache.get_data_structures_manager().remove(key)
except Exception as exp:
    # Handle errors
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

Using Counter in Cache
Configure Searchable Attributes
Configure Invalidation Attributes
Query on Data Structures

Back to top Copyright © 2017 Alachisoft