Try Playground
Show / Hide Table of Contents

Delete Data with Named Tags and SQL Query

NCache provides Object Queries to delete the particular item from the cache having the Named Tag and its value as provided. Ensure that the item is added to the cache with the Named Tags. Refer to the Add Items with Named Tags section to get details on creating and adding Named Tags.

Prerequisites to Delete Data with Named Tags Using SQL Query

  • .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.
  • Custom classes/searchable attributes must be indexed as explained in Configuring Query Indexes.
  • For API details, refer to: ICache, ICacheReader, QueryCommand, Remove, ExecuteNonQuery, 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.
  • Custom classes/searchable attributes must be indexed as explained in Configuring Query Indexes.
  • For API details, refer to: Cache, remove, executeNonQuery, QueryCommand, 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.
  • Custom classes/searchable attributes must be indexed as explained in Configuring Query Indexes.
  • For API details, refer to: Cache, getSearchService, QueryCommand, execute_non_query.
  • 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.
  • Custom classes/searchable attributes must be indexed as explained in Configuring Query Indexes.
  • For API details, refer to: Cache, remove, executeNonQuery, QueryCommand, getSearchService.

Syntax

The following example shows how to delete items associated with a Named Tag using queries.

  • .NET
  • Java
  • Python
  • Node.js
// Preconditions: Cache is already connected
// Items are already present in the cache with Named Tags
// A user wants to end the VIP membership discount offer so this Named Tag needs to be removed from the customer.
// All the customers with VIP membership discount Named Tag needs to be removed from the cache.
// Custom class is query indexed through the NCache Management Center or config.ncconf

// Make sure to use the Fully Qualified Name (FQN)
// Create an SQL Query with the specified criteria

string query = "DELETE FROM Alachisoft.NCache.Samples.Data.Customer WHERE VIP_Membership_Discount = 0.12 ";

// Use QueryCommand for query execution
var queryCommand = new QueryCommand(query);

// 'rowsAffected' indicates the number of items removed from the cache
int rowsAffected = cache.SearchService.ExecuteNonQuery(queryCommand);

if (rowsAffected==0)
    Console.WriteLine($"No VIP members removed");
// Preconditions: Cache is already connected
// Items are already present in the cache with Named Tags
// A user wants to end the VIP membership discount offer So this Named Tag needs to be removed from the customer.
// All the customers with VIP membership discount Named Tag needs to be removed from the cache.
// Custom class is query indexed through the NCache Management Center or config.ncconf

// Make sure to use the Fully Qualified Name (FQN)
// Create an SQL Query to remove customers with VIP membership discount
String query = "DELETE FROM com.alachisoft.ncache.sample.Customer WHERE VIP_Membership_Discount = 0.12 ";

// Use QueryCommand for query execution
QueryCommand queryCommand = new QueryCommand(query);

// 'rowsAffected' indicates the number of items removed from the cache
int rowsAffected = cache.getSearchService().executeNonQuery(queryCommand);

if (rowsAffected > 0)
{
    System.out.println(rowsAffected + " VIP members removed from cache.");
}
else
{
    System.out.println("No VIP members removed");
}
# Preconditions: Cache is already connected
# Items are already present in the cache with Named Tags
# Custom class is query indexed through the NCache Management Center or config.ncconf
# Delete data from cache with the specified criteria

# Make sure to use the Fully Qualified Name(FQN)
query = "DELETE FROM FQN.Product WHERE FlashSaleDiscount = ?"

# Use QueryCommand for query execution
query_command = ncache.QueryCommand(query)

parameter = {"FlashSaleDiscount": 0.5}
query_command.set_parameters(parameter)

search_service = cache.get_search_service()

# 'rows_affected' number of items removed from cache
rows_affected = search_service.execute_non_query(query_command)
// This is an async method
// Preconditions: Cache is already connected
// Items are already present in the cache with Named Tags
// Custom class is query indexed through the NCache Management Center or config.ncconf
// Delete data from cache with the specified criteria
// Make sure to use the Fully Qualified Name (FQN)
var query = "DELETE FROM FQN.Product WHERE FlashSaleDiscount = ?";

// Use QueryCommand for query execution
var queryCommand = new ncache.QueryCommand(query);
var parameters = new Map();
parameters.set("FlashSaleDiscount",0.5);

queryCommand.setParameters(parameters);

var searchService = await this.cache.getSearchService();

// 'rowsAffected' number of items removed from cache
var rowsAffected = await searchService.executeNonQuery(queryCommand);
Note

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

To get more detail on object queries please refer to the SQL Reference for NCache section.

Another approach to removing data with Named Tags is to fetch the data by querying it and then using the Remove method on the fetched data to remove the selected values. Using this approach, the items associated with a specific Named Tag are removed. However, it is not recommended as it will increase the required network calls which is not very efficient for the user. For more details on the remove method, please refer to the Remove Named Tags From Cache Data docs.

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.

In This Article
  • Prerequisites to Delete Data with Named Tags Using SQL Query
  • Syntax
  • Additional Resources
  • See Also

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 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top