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

Remove Existing Data Structure From Cache

You can remove an existing distributed data structure (such as a List, Queue, HashSet, Dictionary, or Counter) from the cache using the Remove method of DataTypeManager or the cache.Remove method. Both approaches safely remove the specified data structure without affecting other cache items, and if the key does not exist, the operation completes without returning a value.

Prerequisites

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

  • .NET
  • Java
  • Node.js
  • Install the following NuGet packages in your .NET client application:
    • Enterprise: Alachisoft.NCache.SDK
    • OpenSource: Alachisoft.NCache.Opensource.SDK
  • Include the following namespaces in your application:
    • Alachisoft.NCache.Client
    • Alachisoft.NCache.Runtime.Exceptions
    • Alachisoft.NCache.Client.DataTypes
    • Alachisoft.NCache.Client.DataTypes.Collections
    • Alachisoft.NCache.Runtime.Caching
    • Alachisoft.NCache.Runtime.Events
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: ICache, DataTypeManager, Contains, Count, Remove.
  • 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.*;
    • import com.alachisoft.ncache.client.datastructures.*;
    • import com.alachisoft.ncache.events.*;
    • import com.alachisoft.ncache.runtime.dependencies.*;
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: Cache, getDataStructuresManager, contains, getCount, remove.
  • Install and include the following module in your Node.js client application:

    • Enterprise: ncache-client
  • Include the following class in your application:

    • Cache
    • DataStructureManager
  • The cache must be running.
  • Make sure that the data being added is serializable.
  • For API details, refer to: Cache, getDataStructuresManager, 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 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.

  • .NET
  • Java
  • Node.js
try
{
  // Precondition: 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
{
  // Precondition: 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
{
  // This is an async method
  // Precondition: Cache is connected

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

  // Remove List from Cache
  const Manager = await this.cache.getDataStructuresManager();
  await Manager.remove(key);
}
catch (error) {
  // 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

.NET: Alachisoft.NCache.Runtime.Caching namespace.
Java: com.alachisoft.ncache.runtime.caching namespace.
Node.js: NamedTagsDictionary 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