• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
  • Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Download
  • Server-side API Programming
  • MapReduce Aggregator
  • Implement and Use Aggregator
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

MapReduce Aggregator Implementation and Usage [Deprecated]

This page provides step-by-step guide on implementing and using MapReduce Aggregator with NCache.

Prerequisites

  • .NET
  • Legacy API
  • To learn about the standard prerequisites required to work with all NCache server-side features, please refer to the given page Server-Side API Prerequisites.
  • The class must be implemented as a Class Library (.dll) in Visual Studio. This will be deployed on NCache cluster.
  • For API details, refer to: ICache, IAggregator, IValueExtractor, Aggregate, AggregateAll, Extract, IExecutionService.
  • 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
  • This should be a class library project using Microsoft Visual Studio.
  • 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.Runtime.Aggregation 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.

The Aggregator and Value Extractor logic can be implemented in classes implementing the interfaces IAggregator and IValueExtractor respectively. These implementations will contain the logic to be executed over the cache item(s) on the server side. Once implemented, this implementation will be deployed on NCache. You can then invoke the cache from your client application to perform the specified Entry Processor logic over the server.

Step 1: Implement IAggregator Interface

Your custom logic is provided in Aggregate and AggregateAll methods in the IAggregator implementation. Aggregate() contains the logic of applying the aggregation operation on the same node (locally) as is with the Combiner. If you wish to combine the values using an aggregator before being sent for further processing in the Reducer, you can use the Aggregate() call.

AggregateAll() contains the logic of applying the aggregation operation in the Reduce Phase. If you wish to combine the values using an aggregator, you can use the AggregateAll() call. The following sample implementation processes give values accordingly and return the result where needed.

Important

Once implemented, deploy this class on NCache by referring to Deploy Providers in the Administrator’s Guide.

  • .NET
  • Legacy API
[Serializable]
public class IntAggregator : IAggregator
{
    string function;

    public IntAggregator(string function)
    {
        this.function = function;
    }

    public object Aggregate(object value)
    {
        return Calculate(value);
    }

    public object AggregateAll(object value)
    {
        return Calculate(value);
    }

    private object Calculate(object value)
    {
        switch (function)
        {
            case "MIN":
                value = int.MinValue;
                return value;
            case "MAX":
                value = int.MaxValue;
                return value;
            default:
                return 0;
        }
    }
    // This class is to be deployed on cache
}
// Using NCache Enterprise 4.9.1

[Serializable]
public class IntAggregator : IAggregator
{
    string function;

    public IntAggregator(string function)
    {
        this.function = function;
    }

    public object Aggregate(object value)
    {
        return calculate(value);
    }

    public object AggregateAll(object value)
    {
        return calculate(value);
    }

    private object calculate(object value)
    {
        switch (function)
        {
            case "MIN":
                value = int.MinValue;
                return value;
            case "MAX":
                value = int.MaxValue;
                return value;
            default:
                return 0;
        }
    }
    // This class is to be deployed on cache
}
Note

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

Step 2: Implement IValueExtractor Interface

Your custom logic is provided in the Extract method, which will extract meaningful information/attributes from the object like the Mapper does in the MapReduce. The returned value may also be null. The following sample implementation processes give values accordingly and return the result where needed.

  • .NET
  • Legacy API
[Serializable]
public class BasicValueExtractor : IValueExtractor
{
    public object Extract(object value)
    {

            if (value.GetType() == typeof(int))
            {
                return value;
            }

            if (value.GetType() == typeof(float))
            {
                return 0.0;
            }

        return value;
    }
    // This class is to be deployed in cache
}
// Using NCache Enterprise 4.9.1

[Serializable]
public class BasicTypeExtractor : IValueExtractor
{
    public object Extract(object value)
    {
            if (value.GetType() == typeof(int))
            {
                return 0;
            }

            if (value.GetType() == typeof(float))
            {
                return 0.0;
            }
        return value;
    }
    // This class is to be deployed on cache
}

Step 3: Deploy Implementations on the Cache

Deploy these custom implementations on NCache by referring to Deploy Providers in the Administrator’s Guide for help.

Step 4: Use Aggregator in the Application

Once the interfaces are implemented and deployed on the cache, you can execute the Aggregator using the Aggregate method in your client application.

The following code sample adds a bulk of items into the cache and then invokes the Aggregator using the keys added to the cache, for which implementation has been provided in IAggregator class.

  • .NET
  • Legacy API
// Data exists in cache
// Precondition:Cache is already connected

int value;

// Get single value by custom implemented aggregator
value = (int)cache.ExecutionService.Aggregate(new BasicValueExtractor(), new IntAggregator("MIN"));

// Get single value by custom implemented aggregator
value = (int)cache.ExecutionService.Aggregate(new BasicValueExtractor(), new IntAggregator("MAX"));

// Using the built-in aggregator
value = (int)cache.ExecutionService.Aggregate(new BasicValueExtractor(), BuiltInAggregator.IntegerSum());
// Using NCache Enterprise 4.9.1
// Data exists in cache
// Precondition:Cache is already connected

int value;

// Using the built-in aggregator
value = (int)cache.Aggregate(new BasicTypeExtractor(),BuiltInAggregator.IntegerSum());

// Get single value by custom implemented aggregator
value = (int)cache.Aggregate(new BasicTypeExtractor(), new IntAggregator("MIN"));

// Get a single value by custom implemented aggregator
value = (int)cache.Aggregate(new BasicTypeExtractor(), new IntAggregator("MAX"));

See Also

Aggregator Components and Working
MapReduce
WAN Replication across Multi Datacenters through Bridge
Deploy Providers

In This Article
  • Prerequisites
  • Step 1: Implement IAggregator Interface
  • Step 2: Implement IValueExtractor Interface
  • Step 3: Deploy Implementations on the Cache
  • Step 4: Use Aggregator in the Application
  • 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 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