• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Remove Cache Data with Groups [Deprecated]

NCache allows the user to remove the items with the cache groups. It also allows the user to remove the data group with CacheItem. To remove cache items from cache 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 present in the cache.

Prerequisites

Before using the NCache Client-side APIs, ensure that the following prerequisites are fulfilled:

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
  • Install the following NuGet packages in your .NET client application:
    • Enterprise: Alachisoft.NCache.SDK
    • Open Source: Alachisoft.NCache.Opensource.SDK
  • Include the following namespaces in your application:
    • Alachisoft.NCache.Client
    • Alachisoft.NCache.Runtime.Exceptions
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: ICache, RemoveGroupData, SearchService.
  • Add the following Maven dependencies for your Java client application in pom.xml file:
<dependency>
    <groupId>com.alachisoft.ncache</groupId>
    <!--for NCache Enterprise-->
    <artifactId>ncache-client</artifactId>
    <version>x.x.x</version>
</dependency>
  • Import the following packages in your Java client application:
    • import com.alachisoft.ncache.client.*;
    • import com.alachisoft.ncache.runtime.exceptions.*;
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: Cache, removeGroupData, getSearchService.
  • Install the following packages in your Python client application:
    • Enterprise: ncache-client
  • Import the following packages in your application:
    • from ncache.client import*
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: Cache, remove_group_data, get_search_service.
  • Install and include the following module in your Node.js client application:
    • Enterprise: ncache-client
  • Include the following class in your application:
    • Cache
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: Cache, removeGroupData, getSearchService.
  • Create a new Console Application.
  • Install either of the following NuGet packages in your .NET client application:
    • Enterprise: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
  • Create a new Console Application.
  • Make sure that the data being added is serializable.
  • Add NCache References by locating %NCHOME%\NCache\bin\assembly\4.0 and adding Alachisoft.NCache.Web and Alachisoft.NCache.Runtime as appropriate.
  • Include the Alachisoft.NCache.Web.Caching namespace in your application.
  • To learn more about the NCache Legacy API, please download the NCache 4.9 documents available as a .zip file on the Alachisoft Website.
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 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
  • Java
  • Python
  • Node.js
  • Legacy API
try
{
  // Precondition: 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);
  Console.WriteLine($"Data of group '{groupName}' has been removed successfully.");
}
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
{
  // Precondition: 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.getSearchService().removeGroupData(groupName);
  System.out.println("Data of group '" + groupName + "' has been removed successfully.");
}
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:
    # Precondition: 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'
    group_name = "West Coast Customers"

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

    print(f"Data of group '{group_name}' has been removed successfully.")

except Exception as error:
    # Exception can occur due to:
    # Connection Failures
    # Operation Timeout
    # Operation during state transfer
    print("An error occurred:", str(error))
try
{
  // Precondition: 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'
  const groupName = "West Coast Customers";

  // Cache items belonging to the group are removed from the cache
  const searchService = await cache.getSearchService();
  await searchService.removeGroupData(groupName);
  console.log(`Data of group '${groupName}' has been removed successfully.`)
}
catch(error)
{
    // Exception can occur due to:
    // Connection Failures 
    // Operation Timeout
    // Operation performed during state transfer
}  
// Using NCache Enterprise 4.9.1

try
{
  // Precondition: Cache is already connected
  // Items are previously added in the cache with the group 'West Coast Customers' and subgroup 'Retail'
  string groupName = "West Coast Customers";
  string subGroupName = "Retail";

  // Cache items belonging to the group are removed from the cache
  cache.RemoveGroupData(groupName, subGroupName);
  Console.WriteLine($"Data of group '{groupName}' and subgroup '{subGroupName}' has been removed successfully.");
}
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
}
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

.NET: Alachisoft.NCache.Client namespace.
Java: com.alachisoft.ncache.client namespace.
Python: ncache.client class.
Node.js: Cache class.

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top