• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
Show / Hide Table of Contents

Retrieve Cache Data with Groups [Deprecated]

Once the items are added to the specific groups in cache data, the user can also retrieve certain cache items or keys associated with that group.

Prerequisites to Retrieve Cache Data with Groups

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
  • 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, GetGroupKeys, GetGroupData, 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.
  • For API details, refer to: Cache, getGroupKeys, getGroupData, 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.
  • For API details, refer to: Cache, get_group_keys, get_group_data, get_search_service.
  • 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, getGroupKeys, getGroupData, getSearchService.
  • 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.

Retrieve Keys of a Particular Group

To return a list of keys that belong to a specified group in cache data, you can use GetGroupKeys method that returns a list of keys mapped under the group passed to this API.

Important
  • Passing empty strings for the group will return an empty result set.
  • Passing only the value of the group will return all the keys mapped under the group.
  • Passing null to this API for the group will throw an ArgumentNullException.
  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// Preconditions: Cache is connected
// A user wants to get the cache keys of all the customers from the West Coast

string groupName = "West Coast Customers";

ICollection<string> keys = cache.SearchService.GetGroupKeys(groupName);

if (keys != null && keys.Count > 0)
{
    // Iterate over the result
    foreach (var key in keys)
    {
        Console.WriteLine($"Key '{key}' belongs to '{groupName}' group.");
    }
}
// Precondition: Cache is connected
// A user wants to get the cache keys of all the customers from the West Coast
String groupName = "West Coast Customers";

Collection<String> keys = null;
keys = cache.getSearchService().getGroupKeys(groupName);

if (keys != null && !keys.isEmpty()) {
    // Iterate over the result
    for (String key : keys) {
        System.out.println("Key '" + key + "' belongs to '" + groupName + "' group.");
    }
}
# Precondition: Cache is connected
# Data with this group already exists in cache
group_name = "Important Customers"

search_service = cache.get_search_service()
retrieved_keys = search_service.get_group_keys(group_name)

if retrieved_keys is not None and len(retrieved_keys) > 0:
    # Iterate over the result
    for key in retrieved_keys:
        # Perform Operations
        print(key)
else:
    # No data against the group found
    print("No keys found")
// Preconditions: Cache is connected
// This is an async method
// Data with this group already exists in cache
var groupName = "Important Customers";

var searchService = await this.cache.getSearchService();
var retrievedKeys = await searchService.getGroupKeys(groupName);

if (retrievedKeys != null && retrievedKeys.size() > 0)
{
    // Iterate over the result
    retrievedKeys.forEach(key => {
        // Perform Operations
    });
}
else
{
    // No data against the group found
}
string groupName = "Product";
string subGroupName = "Beverages";

ArrayList keys = cache.GetGroupKeys(groupName, subGroupName);

    foreach (object obj in keys)
        //do something
Note

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

Retrieve Keys and Values of a Particular Group

To return the dictionary of the keys and the values that belong to a specified group in cache data, the GetGroupData method can be used. This method returns a dictionary of keys and values mapped under the group passed to this API.

The following example retrieves the keys and the values that belong to the group West Coast Customers.

  • .NET
  • Java
  • Python
  • Node.js
  • Legacy API
// A user wants to get the cache keys along with the values of all the customers from the West Coast

string groupName = "West Coast Customers";

IDictionary<string, Customer> retrievedDictionary = cache.SearchService.GetGroupData<Customer>(groupName);

if (retrievedDictionary != null)
{
    foreach (KeyValuePair<string, Customer> retrievedItem in retrievedDictionary)
    {
        Console.WriteLine($"Customer '{retrievedItem.Value.ContactName}' having Key '{retrievedItem.Key}' belongs to West Coast");
    }
}
// A user wants to get the cache keys along with the values of all the customers from the West Coast

String groupName = "West Coast Customers";

Map<String, Customer> retrievedDictionary = null;

retrievedDictionary = cache.getSearchService().<Customer>getGroupData(groupName);

if (retrievedDictionary != null && !retrievedDictionary.isEmpty()) {

    for (java.util.Map.Entry<String, Customer> retrievedItem : retrievedDictionary.entrySet()) {

        System.out.println("Customer '" + retrievedItem.getValue().getCustomerID() + "' having Key '" + retrievedItem.getKey() + "' belongs to West Coast");
    }
}
# Data with this group already exists in cache

group_name = "Important Customers"

search_service = cache.get_search_service()
result = search_service.get_group_data(group_name)

if result is not None and len(result) > 0:
    # Iterate over the result
    for key in result:
        # Perform Operations
        print(result[key])

else:
    # No data against the group found
    print("No data found")
// This is an async method
// Data with this group already exists in cache

var groupName = "Important Customers";

var searchService = await this.cache.getSearchService();
var result = await searchService.getGroupData(groupName);

if (result != null && result.size() > 0)
{
    // Iterate over the result
    result.forEach(item => {

        // Perform Operations
    });
}
else
{
    // No data against the group found
}
string groupName = "Product";
string subGroupName = "Beverages";

ArrayList keys = cache.GetGroupKeys(groupName, subGroupName) as IDictionary;

    if (data.Count > 0)
    {
        IDictionaryEnumerator result = data.GetEnumerator();

        while (result.MoveNext())
        {
            string key = (string)result.Key;
            Product val = (Product)result.Value;
            //do something
        }
    }

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.

In This Article
  • Prerequisites to Retrieve Cache Data with Groups
  • Retrieve Keys of a Particular Group
  • Retrieve Keys and Values of a Particular Group
  • 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