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

Remove Cache Data with Group

Note

This feature is only available in NCache Enterprise Edition.

NCache allows the user to remove the items with the data groups. It also allows the user to remove the data group with CacheItem.

To remove cache items that belong to a specific group, the RemoveGroupData method can be used. This method removes all the cache items mapped under the group passed to this API.

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, RemoveGroupData, SearchService.
  • 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, removeGroupData, getSearchService.
  • 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, SearchService.
  • 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, removeGroupData, getSearchService.
  • 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, remove_group_data, get_search_service.
Important
  • Passing empty strings for the group will return an empty result set.
  • Passing null for the group will throw an ArgumentNullException.
  • Passing only the the value of the group will remove all the cache items mapped under the group.

The following example removes the data under the group West Coast Customers.

  • .NET/.NET Core
  • Java
  • Scala
  • Node.js
  • Python
try
{
    // Pre-conditions: Cache is already connected

    // A user wants to remove a customer from West Coast Region

    // Items are previously added in the cache with the group 'West Coast Customers' 
    string groupName = "West Coast Customers";

    // Cache items belonging to the group are removed from the cache       
    cache.SearchService.RemoveGroupData(groupName);
 }
catch (OperationFailedException ex)
{
    // Exception can occur due to:
    // Connection Failures 
    // Operation Timeout
    // Operation performed during state transfer
}
catch (Exception ex)
{
    // Any generic exception like ArgumentNullException or ArgumentException
}
try
{
    // Pre-condition: Cache is already connected

    // Items are previously added in the cache with group 'ImportantCustomers'
    String groupName = "ImportantCustomers";

    // Cache items belonging to the group are removed from the cache
    cache.getSearchService().removeGroupData(groupName);
}
catch (OperationFailedException ex)
{
    // 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 already connected

    // Items are previously added in the cache with group 'ImportantCustomers'
    val groupName = "ImportantCustomers"

    // Cache items belonging to the group are removed from the cache
    cache.getSearchService.removeGroupData(groupName)
}
catch {
    case exception: Exception => {
      // Handle any errors
    }
}
try
{
    // Pre-condition: Cache is already connected

    // Items are previously added in the cache with group 'ImportantCustomers' 
    var groupName = "ImportantCustomers";

    // Cache items belonging to the group are removed from the cache       
    var searchService = await this.cache.getSearchService();
    var retrievedKeys = await searchService.removeGroupData(groupName);
}
catch(error)
{
    // Exception can occur due to:
    // Connection Failures 
    // Operation Timeout
    // Operation performed during state transfer
}
 try:
    # Pre-condition: Cache is already connected

    # Items are previously added in the cache with group 'ImportantCustomers'
    group_name = "ImportantCustomers"

    # Cache items belonging to the group are removed from the cache
    search_service = cache.get_search_service()
    retrieved_keys = search_service.remove_group_data(group_name)

except Exception as exp:
    # Exception can occur due to:
    # Connection Failures Operation Timeout
    # Operation performed during state transfer
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 Groups on GitHub.

See Also

Add/Update Cache Data with Groups
Retrieve Cache Data with Groups
Basic Operations for Caching Data
Tag Cache Data

Back to top Copyright © 2017 Alachisoft