• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
  • Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Download
  • Client Side API Programming
  • Groups
  • Retrieve Data with Groups
Show / Hide Table of Contents
  • Programmer's Guide
  • Setting Up Development Environment
    • .NET
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Java
      • Client API Prerequisites
    • Python
      • Client API Prerequisites
    • Node.js
      • Client API Prerequisites
  • Client Side API Programming
    • Error Handling
    • Troubleshooting
    • Cache Keys and Data
    • How to Connect to Cache
    • Basic Operations - An Overview
      • Add Data
      • Update/Insert Data
      • Retrieve Data
      • Remove Data
    • Groups
      • Overview
      • Add/Update Data with Groups
      • Retrieve Data with Groups
      • Remove Data with Group
      • Search Group Data Using SQL
      • Delete Group Data Using SQL
    • Tags
      • Overview
      • Add/Update Data with Tags
      • Retrieve Data with Tags
      • Remove Data with Tags
      • Search Tag Data Using SQL
      • Delete Tag Data Using SQL
    • Named Tags
      • Overview
      • Add/Update Data with Named Tags
      • Remove Data with Named Tags
      • Search Data with Named Tags Using SQL
      • Delete Data with Named Tags Using SQL
    • Expirations
      • Overview
      • Absolute Expiration
      • Sliding Expiration
    • Data Dependency
      • Key Dependency
      • Multi-Cache Dependency
    • Dependency on Database
      • SQL Dependency
      • Oracle Dependency
      • OleDB Dependency
      • CLR Procedures in SQL Server
    • Dependency on External Source
      • File Dependency
      • Custom Dependency
      • Aggregate Dependency
    • Locks
      • Types of Locking
      • Pessimistic Locking
      • Optimistic Locking
    • SQL Query
      • Overview
      • Define Indexes Programmatically
      • Query with ExecuteReader and ExecuteScalar
      • Delete Data with ExecuteNonQuery
      • SQL Reference
    • LINQ Query
      • Overview
      • LINQ Query for Objects
      • LINQ Reference
    • Data Structures
      • Overview
      • List
      • Queue
      • Set
      • Dictionary
      • Counter
      • Invalidation Attributes
      • Searchable Attributes
      • Query on Data Structures
      • Remove from Data Structure
    • Events
      • Overview
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Pub/Sub Topics
      • Publish Messages to a Topic
      • Subscribe to a Topic
      • Monitoring Pub/Sub Topics
    • Continuous Query
      • Overview
      • Use Continuous Query
    • Stream Processing
      • Add/Update Stream Data
      • Retrieve Stream Data
    • JSON
      • Overview
      • Use JSON Objects
      • Query JSON Data
    • Security API
      • Login with Credentials
    • Management API
    • Error Logging
    • Location Affinity
  • Server-side API Programming
    • Loader and Refresher
      • Overview
      • Implement Loader and Refresher
      • Components of Loader/Refresher
    • Data Source Providers
      • Read-through
        • Implement Read-through
        • Use Read-through
      • Write-through
        • Implement Write-through
        • Use Write-through
        • Use Write-behind
    • Custom Dependency
      • Implement Extensible Dependency
      • Implement Bulk Extensible Dependency
      • Implement Notify Extensible Dependency
    • Bridge Conflict Resolver
    • Entry Processor
      • Overview
      • Implement Entry Processor
    • MapReduce
      • Overview
      • Implement MapReduce
      • Use MapReduce
    • MapReduce Aggregator
      • Overview
      • Implement and Use Aggregator
    • Compact Serialization
  • Client Side Features
    • ASP.NET Core Caching
      • Session Storage
        • Session Provider
        • IDistributedCache
        • Sessions Usage
        • Multi-site Session Provider
        • Session Sharing with ASP.NET
      • SignalR
        • SignalR Core Integration for NCache
      • Response Caching
        • Configure and Use
        • Configure with IDistributedCache
      • Data Caching
        • NCache API
        • IDistributedCache API
      • Data Protection Provider
        • Configure
    • Java Web App Caching
      • Web Sessions
        • Overview
        • Configure App
          • Add Maven Dependencies
          • Deploy Application
        • Multi-site Sessions
    • Node.js App Caching
      • Web Sessions
    • ASP.NET Caching Benefits and Overview
      • ASP.NET Session State Provider Properties
      • Multi-region ASP.NET Session State Provider Configuration
      • Session Sharing between ASP.NET and ASP.NET Core
      • ASP.NET SignalR Backplane
        • NCache Extension for SignalR
      • ASP.NET View State Caching
        • View State Content Optimization Configuration
        • Group View State with Sessions
        • Limit View State Caching
        • Page Level Grouping
      • ASP.NET Output Cache
        • Output Caching Provider Overview
        • Output Cache with Custom Hooks
  • .NET Third Party Integrations
    • Entity Framework (EF) Core
      • Installation
      • Configure
      • EF Core Extension Methods
        • Extension Methods
        • Cache Handle
        • Caching Options
        • Query Deferred API
      • Logging in EF Core
    • Entity Framework EF 6
      • EF Second Level Cache
      • EF Caching Resync Provider
      • EF Caching Configuration File
    • NHibernate
      • Second Level Cache
      • Query Caching
      • Synchronize Database with Cache
    • Debug NCache Providers in Visual Studio
  • Java Third Party Integrations
    • Hibernate
      • Second Level Cache
      • Configure Cacheable Objects and Regions
      • Configure Application
      • Query Caching
    • Spring
      • Overview
      • Use NCache with Spring
        • Configure Generic Provider
        • Configure JCache Spring Caching Provider
        • Configure Caching Declaration
        • Configure Spring Sessions
    • JCache API
      • CRUD Operations
      • Expiration
      • Events
  • Third-Party Wrappers
    • AppFabric to NCache Migration
      • AppFabric API vs. NCache API
      • Configuration Differences Between AppFabric and NCache
      • Migrating from an AppFabric Application to NCache
    • Redis to NCache Migration
      • Redis to NCache Migration
    • Memcached Wrapper
      • Memcached Gateway Approach
      • Memcached Client Plugin for .NET

Retrieve Cache Data with Groups [Deprecated]

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

Prerequisites

  • .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.
  • Install either of the following NuGet packages in your .NET client application:
    • Enterprise: Install-Package Alachisoft.NCache.SDK -Version 4.9.1.0
    • Professional: Install-Package Alachisoft.NCache.Professional.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.

Retrieve Keys of a Particular Group

To return a list of keys that belong to a specified group in cache, 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
// Precondition: Cache is connected
// Data with this group already exists in cache
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
// Data with this group already exists in cache
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 = "West Coast 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")
// Precondition: Cache is connected
// This is an async method
// Data with this group already exists in cache
var groupName = "West Coast 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
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is connected
// Data with this group already exists in cache

string groupName = "West Coast Customers";
string subGroupName = "Retail"; // Example subgroup

// Fetch keys from cache using legacy API for both group and subgroup
ArrayList keys = cache.GetGroupKeys(groupName, subGroupName);

if (keys != null && keys.Count > 0)
{
    foreach (object key in keys)
    {
        Console.WriteLine("Key '" + key + "' belongs to group '" + groupName + "' and subgroup '" + subGroupName + "'.");
    }
}
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, 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
// Precondition: Cache is connected
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");
    }
}
// Precondition: Cache is connected
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");
    }
}
# Precondition: Cache is connected
# 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
// Precondition: Cache is connected
// 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
}
// Using NCache Enterprise 4.9.1
// Precondition: Cache is connected

string groupName = "West Coast Customers";
string subGroupName = "Retail";

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

if (keys != null && keys.Count > 0)
{
    foreach (string key in keys)
    {
        Customer customer = cache.Get(key) as Customer;
        if (customer != null)
        {
            Console.WriteLine($"Customer '{customer.ContactName}' having Key '{key}' belongs to '{groupName}'");
        }
    }
}

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
  • Retrieve Keys of a Particular Group
  • Retrieve Keys and Values of a Particular Group
  • Additional Resources
  • See Also

Contact Us

PHONE

+1 214-619-2601   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

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