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

Bulk Operations

Bulk operations allow applications to process multiple cache entries in a single network call, significantly reducing network overhead and improving throughput in high-load environments.

Instead of executing individual cache operations for each item, NCache enables you to add, update, retrieve, and remove multiple items in batches. This approach improves performance, minimizes network round-trips, and is recommended when working with large datasets.

Prerequisites

  • .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, Add, Insert, CacheItem, CacheItemVersion, Count, Contains, AddBulk, GetCacheItemBulk, GetBulk, InsertBulk, RemoveBulk.
  • 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, add, insert, CacheItem, CacheItemVersion, getCount, insertBulk, addBulk, getBulk, getCacheItemBulk, removeBulk.
  • 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, CacheItem, CacheItemVersion, add, add_bulk, insert, insert_bulk, get_bulk, get_cacheitem_bulk, remove_bulk.
  • 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, CacheItem, CacheItemVersion, add, addBulk, insert, insertBulk, getBulk, getCacheItemBulk, removeBulk.
  • 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.

Add Bulk Items To Cache

AddBulk adds an array of CacheItem to the cache with the corresponding cache keys. This method returns a dictionary of all the keys that failed to add, along with the failure reason.

Note

For any keys that fail to add, the failure reason will be returned as an IDictionary.

The following code adds a bulk of product items to the cache. If there are any keys that failed to add, the keys can be handled according to your business needs.

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// Precondition: Cache is already connected
// Create an array of all Customer Keys
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary<string, CacheItem> itemsFetched = cache.GetCacheItemBulk(keys);

// Fetch items from DB which do not exist in Cache
if (itemsFetched.Count < keys.Length)
{
    // Create dictionary of items to be added to cache
    IDictionary<string, CacheItem> missingItems = new Dictionary<string, CacheItem>();

    foreach (string key in keys)
    {
        if (!itemsFetched.ContainsKey(key))
        {
            Customer customer = FetchCustomerFromDB(key);
            CacheItem cacheItem = new CacheItem(customer);
            missingItems.Add(key, cacheItem);
        }
    }

    // Add bulk items to Cache
    IDictionary<string, Exception> keysFailedToAdd = cache.AddBulk(missingItems);

    if (keysFailedToAdd.Count > 0)
    {
        foreach(KeyValuePair<string,Exception> keyFailedToAdd in keysFailedToAdd)
            Console.WriteLine($"Could not add Item {keyFailedToAdd.Key} in cache due to error : {keyFailedToAdd.Value}");
    }
}
// Precondition: Cache is already connected
List<String> keys = List.of(
        "Customer:ALFKI",
        "Customer:ANATR",
        "Customer:ANTON",
        "Customer:AROUT",
        "Customer:BERGS"
);

// Get items from cache
Map<String, CacheItem> itemsFetched = cache.getCacheItemBulk(keys);

// Fetch items from DB which do not exist in Cache
if (itemsFetched.size() < keys.size()) {
    // Create dictionary of items to be added to cache
    Map<String, CacheItem> missingItems = new HashMap<>();

    for (String key : keys) {
        if (!itemsFetched.containsKey(key)) {
            Customer customer = fetchCustomerFromDB(key);
            CacheItem cacheItem = new CacheItem(customer);
            missingItems.put(key, cacheItem);
        }
    }

    // Add bulk items to Cache
    Map<String, Exception> keysFailedToAdd = cache.addBulk(missingItems);

    if (keysFailedToAdd.size() > 0) {
        for (Map.Entry<String, Exception> keyFailedToAdd : keysFailedToAdd.entrySet()) {
            System.out.println("Could not add Item " + keyFailedToAdd.getKey() + " in cache due to error: " + keyFailedToAdd.getValue());
        }
    }
}
# Precondition: Cache is already connected
# Fetch all products from database
products = fetch_products_from_db()

# Create map of items to be added to cache
dictionary = {}

for product in products:
    key = "Product:" + product.get_product_id()
    cache_item = ncache.CacheItem(product)

    # Add items to dictionary
    dictionary[key] = cache_item

keys_failed_to_add = cache.add_bulk(dictionary)

if len(keys_failed_to_add) > 0:
    for entry in keys_failed_to_add:
        if not keys_failed_to_add[entry]:
            value = False
else:
    # Any other exception
    value = True
// Precondition: Cache is already connected
// This is an async method
// Fetch all products from database
var products = await this.fetchProductFromDB();

// Create map of items to be added to cache
var dictionary = new map();

products.forEach(prod => {
    var key = "Product:" + this.product.getProductID();
    var cacheItem = new ncache.CacheItem(prod);

    // Add items to dictionary
    dictionary.set(key,cacheItem);
});

var keysFailedToAdd = this.cache.addBulk(dictionary);

if(keysFailedToAdd.size() > 0)
{
    keysFailedToAdd.forEach(entry => {
        if(entry.getValue() == false)
        {
            var value = false;
        }
        else
        {
            // Any other exception
        }
    });
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected
// Create an array of all customer keys
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary itemsFetched = cache.GetBulk(keys);

// Fetch items from DB which do not exist in cache
if (itemsFetched.Count < keys.Length)
{
    // Create dictionary of items to be added to cache
    IDictionary<string, CacheItem> missingItems = new Dictionary<string, CacheItem>();

    foreach (string key in keys)
    {
        if (!itemsFetched.Contains(key))
        {
            Customer customer = FetchCustomerFromDB(key);
            if (customer != null)
            {
                CacheItem cacheItem = new CacheItem(customer);
                missingItems.Add(key, cacheItem);
            }
        }
    }

    string[] missingKeys = new string[missingItems.Count];
    CacheItem[] missingCacheItems = new CacheItem[missingItems.Count];
    int index = 0;
    foreach (var keyValuePair in missingItems)
    {
        missingKeys[index] = keyValuePair.Key;
        missingCacheItems[index] = keyValuePair.Value;
        index++;
    }

    // Add bulk items to cache
    IDictionary keysFailedToAdd = cache.AddBulk(missingKeys, missingCacheItems);

    if (keysFailedToAdd.Count > 0)
    {
        foreach (DictionaryEntry entry in keysFailedToAdd)
        {
            Console.WriteLine($"Could not add Item {entry.Key} in cache due to error: {entry.Value}");
        }
    }
}

Update Bulk Items in Cache

The InsertBulk API is essential for high-load scenarios, as it significantly reduces network round-trips by combining multiple update operations into a single network packet.

InsertBulk updates an array of Cache​Item to the cache against the corresponding key. The method returns a dictionary of all the keys that failed to update, along with the failure reason.

Important

If any keys fail to update, their reasons of failure will be returned as an IDictionary.

The following code example fetches an array of Customers from the database. The Customers are then inserted to the cache as a dictionary of keys and CacheItem using InsertBulk.

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// Precondition: Cache is already connected
// Create an array of all Customer Keys
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary<string, Customer> itemsFetched = cache.GetBulk<Customer>(keys);

// Create a dictionary to store updated items
IDictionary<string, CacheItem> itemsUpdated = new Dictionary<string, CacheItem>();

// Update postal codes of dictionary items
foreach (KeyValuePair<string, Customer> item in itemsFetched)
{
    // Update Postal Code
    item.Value.PostalCode = "05023";

    // Create CacheItem of updated Customer object
    CacheItem updatedCacheItem = new CacheItem(item.Value);

    // Add CacheItem to dictionary
    itemsUpdated.Add(item.Key,updatedCacheItem);
}

if (UpdateDB(itemsUpdated))
{
    // Insert updated bulk items to Cache
    IDictionary<string, Exception> keysFailedToInsert = cache.InsertBulk(itemsUpdated);

    if (keysFailedToInsert.Count > 0)
    {
        foreach (KeyValuePair<string, Exception> keyFailedToInsert in keysFailedToInsert)
            Console.WriteLine($"Could not update Item {keyFailedToInsert.Key} in cache due to error : {keyFailedToInsert.Value}");
    }
}
// Precondition: Cache is already connected
// Create an array of all Customer Keys
List<String> keys = List.of(
        "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
);

// Get items from cache
Map<String, Customer> itemsFetched = cache.getBulk(keys, Customer.class);

// Create a dictionary to store updated items
Map<String, CacheItem> itemsUpdated = new HashMap<>();

// Update postal codes of dictionary items
for (Map.Entry<String, Customer> item : itemsFetched.entrySet()) {
    // Update Postal Code
    item.getValue().setPostalCode("05023");

    // Create CacheItem of updated Customer object
    CacheItem updatedCacheItem = new CacheItem(item.getValue());

    // Add uCacheItem to dictionary
    itemsUpdated.put(item.getKey(), updatedCacheItem);
}

if (updateDB(itemsUpdated)) {
    // Insert updated bulk items to Cache
    Map<String, Exception> keysFailedToInsert = cache.insertBulk(itemsUpdated);

    if (keysFailedToInsert.size() > 0) {
        for (Map.Entry<String, Exception> keyFailedToInsert : keysFailedToInsert.entrySet()) {
            System.out.printf("Could not update Item %s in cache due to error : %s", keyFailedToInsert.getKey(), keyFailedToInsert.getValue());
        }
    }
}
# Precondition: Cache is already connected
# Fetch all products from database
products = fetch_products_from_db()

# Create map of items to be inserted to cache
dictionary = {}

for product in products:
    key = "Product:" + product.get_product_id()
    cache_item = ncache.CacheItem(product)

    # Add items to dictionary
    dictionary[key] = cache_item

keys_failed_to_insert = cache.insert_bulk(dictionary)

if len(keys_failed_to_insert) > 0:
    for entry in keys_failed_to_insert:
        if not keys_failed_to_insert[entry]:
            value = False
else:
    # Any other exception
    value = True
// Precondition: Cache is already connected
// Fetch all products from database
var products = await this.fetchProductFromDB();

// Create map of items to be added to cache
var dictionary = new Map();

products.forEach(prod => {
    var key = "Product:" + this.product.getProductID();
    var cacheItem = new ncache.CacheItem(this.product);

    // Insert dictionary to cache
    this.cache.insert(key,cacheItem);
});

var keysFailedToAdd = this.cache.addBulk(dictionary);

if(keysFailedToAdd.size() > 0)
{
    keysFailedToAdd.forEach(entry => {
        if(entry.getValue() == false)
        {
            var ex = false;
        }
        else
        {
            // Any other exception
        }
    });
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected
// Create an array of all Customer Keys
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Create an array of all Customer Keys
IDictionary itemsFetched = cache.GetBulk(keys);

if (itemsFetched.Count < keys.Length)
{
    // Create a dictionary to store updated items
    IDictionary<string, CacheItem> missingItems = new Dictionary<string, CacheItem>();


    // Update dictionary items
    foreach (string key in keys)
    {
        if (!itemsFetched.Contains(key))
        {
            Customer customer = FetchCustomerFromDB(key);
            if (customer != null)
            {
                // Create CacheItem of updated Customer object
                CacheItem cacheItem = new CacheItem(customer);

                // Add CacheItem to dictionary
                missingItems.Add(key, cacheItem);
            }
        }
    }

    string[] missingKeys = new string[missingItems.Count];
    CacheItem[] missingCacheItems = new CacheItem[missingItems.Count];
    int index = 0;
    foreach (var keyValuePair in missingItems)
    {
        missingKeys[index] = keyValuePair.Key;
        missingCacheItems[index] = keyValuePair.Value;
        index++;
    }

    // Insert updated bulk items to Cache
    IDictionary keysFailedToAdd = cache.InsertBulk(missingKeys, missingCacheItems);

    if (keysFailedToAdd.Count > 0)
    {
        foreach (DictionaryEntry entry in keysFailedToAdd)
        {
            Console.WriteLine($"Could not add Item {entry.Key} in cache due to error: {entry.Value}");
        }
    }
}

Retrieve Bulk Items from Cache

NCache allows synchronous bulk retrieval of items in a single call to reduce network costs. Various overloads of the GetBulk method retrieve objects from the cache data for the cache keys specified. GetBulk significantly reduces network round-trips by bundling multiple requests into a single network packet, which is critical for high-load environments. Note that the value is retrieved as a template so it needs to be type cast accordingly if it is a custom class object.

Important

If the keys exist in the cache, a dictionary of cache items and their keys is returned.

The following example retrieves any existing CacheItem that contains an object of the Customer class. The result is returned in an IDictionary of keys and values, which can be enumerated to get the actual values of the keys. Since GetBulk returns a template (that needs to be cast), the object is cast to the Customer type in this example. If the specified key does not exist in the cache, a null value is returned.

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// Precondition: Cache is already connected
// Create an array of all keys to fetch
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary<string, Customer> retrievedItems = cache.GetBulk<Customer>(keys);

// Retrieve customers and their addresses from dictionary
foreach (KeyValuePair<string, Customer> retrievedItem in retrievedItems)
{
    Console.WriteLine($"Customer: {retrievedItem.Value.ContactName}, Address : {retrievedItem.Value.Address}");
}
// Precondition: Cache is already connected
// Create an list of all keys to fetch
List<String> keys = List.of(
        "Customer:ALFKI",
        "Customer:ANATR",
        "Customer:ANTON",
        "Customer:AROUT",
        "Customer:BERGS"
);

// Get items from cache
Map<String, Customer> retrievedItems = cache.getBulk(keys, Customer.class);

// Retrieve customers and their addresses from dictionary
for (Map.Entry<String, Customer> retrievedItem : retrievedItems.entrySet())
{
    System.out.println("Customer: " + retrievedItem.getValue().getContactName() + ", Address: " + retrievedItem.getValue().getAddress());
}
# Precondition: Cache is already connected
# Get Products from database
products = fetch_products_from_db()

# Get keys to fetch from cache
keys = []
index = 0

for product in products:
    keys.append( "Product:" + product.get_product_id())

# Get bulk from cache
retrieved_items = cache.get_bulk(keys, Product)

# Check if any keys have failed to be retrieved
if len(retrieved_items) is len(keys):
    # Perform operations according to business logic
    print("All the items were retrieved successfully")
else:
    # Not all the keys are present in cache
    print("Some of the keys were not found")
// Precondition: Cache is already connected
// This is an async method
// Get Product from database against given ProductID
var products = await this.fetchProductFromDB();

// Get keys to fetch from cache
var keys = [products.length];
var index = 0;

products.forEach(product => {

    keys[index] ="Product:" + this.product.getProductID();
    index++;

});

// Get bulk from cache
var retrievedItems = await this.cache.getBulk(keys,Product);

// Check if any keys have failed to be retrieved
if(retrievedItems.size() == keys.length)
{
    retrievedItems.forEach(entry => {

        if(entry.getValue() instanceof Product)
        {
            // Perform operations according to business logic
        }
        else
        {
            // Object not of Product type
        }
    });
}
else
{
    // Not all of the keys are present in cache
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected
// Create an array of all keys to fetch
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary retrievedItems = cache.GetBulk(keys);

// Retrieve customers and their addresses from dictionary
foreach (DictionaryEntry entry in retrievedItems)
{
    string key = (string)entry.Key;
    Customer customer = (Customer)entry.Value;

    Console.WriteLine($"Customer: {customer.ContactName}, Address: {customer.Region}");
}

Retrieve Bulk of CacheItems from Cache

You can also retrieve a bulk of CacheItem using the GetCacheItemBulk method. Here is an example:

  • .NET
  • Java
  • Python
  • Node.js
// Precondition: Cache is already connected
// Create an array of all keys to fetch
String[] keys = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Get items from cache
IDictionary<string, Customer> retrievedItems = cache.GetBulk<Customer>(keys);

// Retrieve customers and their addresses from dictionary
foreach (KeyValuePair<string, Customer> retrievedItem in retrievedItems)
{
    Console.WriteLine($"Customer: {retrievedItem.Value.ContactName}, Address : { retrievedItem.Value.Address}");
}
// Precondition: Cache is already connected
// Create an array of all keys to fetch
List<String> keys = List.of(
        "Customer:ALFKI",
        "Customer:ANATR",
        "Customer:ANTON",
        "Customer:AROUT",
        "Customer:BERGS"
);

// Get items from cache
Map<String, Customer> retrievedItems = cache.getBulk(keys, Customer.class);

// Retrieve customers and their addresses from map
for (Map.Entry<String, Customer> retrievedItem : retrievedItems.entrySet()) {
    Customer customer = retrievedItem.getValue();
    System.out.println("Customer: " + customer.getName() + ", Address: " + customer.getPostalCode());
}
# Precondition: Cache is already connected
# Get Products from database
products = fetch_products_from_db()

# Get keys to fetch from cache
keys = []
index = 0

for product in products:
    keys.append( "Product:" + product.get_product_id())

# Get bulk from cache
retrieved_items = cache.get_cacheitem_bulk(keys)

# Check if any keys have failed to be retrieved
if len(retrieved_items) is len(keys):
    for item in retrieved_items:
        product = retrieved_items[item].get_value(Product)
        # Perform operations according to business logic
else:
    # Not all the keys are present in cache
    print("Some of the keys were not found")
// Precondition: Cache is already connected
// This is an async method
// Get Product from database against given ProductID
var products = await this.fetchProductFromDB();

// Get keys to fetch from cache
var keys = [products.length];
var index = 0;

products.forEach(product => {
    keys[index] ="Product:" + this.product.getProductID();
    index++;
});

// Get bulk from cache
var retrievedItems = this.cache.getCacheItemBulk(keys);

// Check if any keys have failed to be retrieved
if(retrievedItems.size() == keys.length)
{
    retrievedItems.forEach(entry => {
        if(entry.getValue() instanceof ncache.CacheItem)
        {
            var prod = entry.getValue();

            // Perform operations according to business logic
        }
        else
        {
            // Object not of Product type
        }
    });
}
else
{
    // Not all of the keys are present in cache

    keys.forEach(key => {

        if(retrievedItems.containsKey(key) == false)
        {
            //  key does not exist in cache
        }
    });
}

Remove Bulk Items From Cache

NCache provides a RemoveBulk method to remove a bulk of cache items against the specified array of cache keys. It returns a dictionary of the keys and objects removed from the cache.

Important

If the specified items exist in the cache, a dictionary of the keys and objects removed is returned.

Tip

One quick way to verify whether an item has been removed is to use either of the following properties of the cache class:

  • Count returns the number of items present in the cache.
  • Contains verifies if a specified key exists in the cache.

The following example removes a bulk of existing cache items and casts the returned object into Customer objects.

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// Precondition: Cache is already connected
// Create an array of all keys to remove
String[] keysToRemove = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Create dictionary to store removed items
IDictionary<string, Customer> removedItems;

// Remove items from DB
if (DeleteFromDB(keysToRemove))
{
    // Remove bulk items from cache
    cache.RemoveBulk(keysToRemove, out removedItems);
    // Check for failed removals
    if (removedItems.Count != keysToRemove.Length)
    {
        Console.WriteLine($"Failed to remove {keysToRemove.Length - removedItems.Count} items from cache.");
    }
}
// Precondition: Cache is already connected
// Create an array of all keys to remove
var keysToRemove = List.of("Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS");

// Create dictionary to store removed items
Map<String, Customer> removedItems;

// Remove items from DB
if (deleteFromDB(keysToRemove)) {

    // Remove bulk items from cache
    removedItems = cache.removeBulk(keysToRemove, Customer.class);

    // Check for failed removals
    if (removedItems.size() != keysToRemove.size())
        System.out.println("Failed to remove " + (keysToRemove.size() - removedItems.size()) + " items from cache.");
}
# Precondition: Cache is already connected
# Create an array of all keys to remove
products = fetch_products_from_db()
keys = []
index = 0

for product in products:
    keys[index] = "Product:" + product.get_product_id()
    index = index + 1

# Remove bulk from cache
removed_items = cache.remove_bulk(keys, Product)

# Check for failed removals
if len(removed_items) is len(keys):
    # Perform operations according to business logic
    print("All the items were removed successfully")
else:
    # Not all the keys are present in cache
    print("Some of the keys were not removed")
// Precondition: Cache is already connected
// This is an async method
// Create an array of all keys to remove
var products = await this.fetchProductFromDB();
var keys = [products.length];
var index = 0;

products.forEach(product => {
    keys[index] ="Product:" + this.product.getProductID();
    index++;
});

// Get bulk from cache
var removedItems = await this.cache.removeBulk(keys);

// Check for failed removals
if(removedItems.size() > 0)
{
    removedItems.forEach(entry => {

        if(entry.getValue() instanceof Product)
        {
            var prod = entry.getValue();
            // Perform operations according to business logic
        }
        else
        {
            // Object not of Product type
        }
    });
}
else
{
    // No objects removed
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is already connected

// Create an array of all keys to remove
String[] keysToRemove = new String[]
{
    "Customer:ALFKI", "Customer:ANATR", "Customer:ANTON", "Customer:AROUT", "Customer:BERGS"
};

// Remove items from cache
IDictionary removedItems = cache.RemoveBulk(keysToRemove);

// Check for failed removals
if (removedItems.Count < keysToRemove.Length)
{
    var missingKeys = new HashSet<string>(keysToRemove);
    foreach (DictionaryEntry entry in removedItems)
    {
        missingKeys.Remove((string)entry.Key);
        Console.WriteLine($"Failed to remove {keysToRemove.Length - removedItems.Count} items from cache.");
    }
}

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