Try Playground
Show / Hide Table of Contents

Remove Data with Named Tags From Data Cache

The items added with Named Tags to the data cache can also be removed from the data cache using the same Named Tags. Additionally, like updating Named Tags, they can also be removed via CacheItem. This is a custom class provided by NCache which can be used to add data to the data cache. To remove Named Tag via CacheItem, the Named Tagproperty of the CacheItem is set as null.

Prerequisites

  • .NET
  • Java
  • Python
  • Node.js
  • 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, CacheItem, NamedTags, GetCacheItem, Insert, 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, CacheItem, NamedTagsDictionary, getCacheItem, insert.
  • 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, CacheItem, insert, get_cacheitem, set_named_tags, NamedTagsDictionary.
  • 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, CacheItem, NamedTagsDictionary, getCacheItem, insert, setNamedTags.

The following example removes the Named Tags via CacheItem.

  • .NET
  • Java
  • Python
  • Node.js
// Precondition: Cache is already connected
// A User wants to end the VIP membership discount offer
// So this Named Tag needs to be removed.

string customerKey = $"Customer:ALFKI";

// Retrieve the CacheItem using the key
CacheItem cacheItem = cache.GetCacheItem(customerKey);

// Remove tag from dictionary
cacheItem.NamedTags.Remove("VIP_Membership_Discount");

// Reinsert the cacheItem in the cache with Named Tags removed
cache.Insert(customerKey, cacheItem);
// Precondition: Cache is already connected
// A User wants to end the VIP membership discount offer
// So this Named Tag needs to be removed.

String customerKey = "Customer:ALFKI";

// Retrieve the CacheItem using the key
CacheItem cacheItem = cache.getCacheItem(customerKey);

// Remove tag from dictionary
cacheItem.getNamedTags().remove("VIP_Membership_Discount");

// Reinsert the cacheItem in the cache with Named Tags removed
cache.insert(customerKey, cacheItem);
# Precondition: Cache is already connected
# CacheItem is already added in the cache with Named Tags with this key

key = "Product:1001"

# Retrieve the CacheItem using the key
cache_item = cache.get_cacheitem(key)

# Set the Named Tags property of the cacheItem as null
cache_item.set_named_tags(None)

# Re-insert the cacheItem in the cache with Named Tags removed
cache.insert(key, cache_item)

# CacheItem is successfully re-inserted in cache with removed Named Tags
// This is an async method
// Precondition: Cache is already connected
// CacheItem is already added in the cache with Named Tags with this key

var key = "Product:1001";

// Retrieve the CacheItem using the key
var cacheItem = await this.cache.getCacheItem(key);

// Set the Named Tags property of the cacheItem as null
cacheItem.setNamedTags(null);

// Re-insert the cacheItem in the cache with Named Tags removed
await this.cache.insert(key, cacheItem);

// CacheItem is successfully re-inserted in cache with removed Named Tags
Note

To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures.

Note

The cacheItem.NamedTags.Remove(tagName) method will remove the Named Tag associated with the tag name tagName. If all Named Tags are removed from the Named Tags dictionary and the cache item is then inserted into the cache, Named Tags will be removed from that cache item since an empty Named Tags dictionary indicates no Named Tags.

Additional Resources

NCache provides a sample application for Tags on GitHub.

See also

.NET: Alachisoft.NCache.Runtime.Caching namespace.
Java: com.alachisoft.ncache.runtime.caching namespace.
Python: ncache.runtime.caching class.
Node.js: NamedTagsDictionary class.

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • 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