Try Playground
Show / Hide Table of Contents

Using MapReduce in Cache [Deprecated]

To use the MapReduce, initialize the MapReduce Task. Set the mapper, Combiner, and the Reducer factory to the task and then execute the task on the cache.

Note

This feature is only available in the NCache Enterprise.

Prerequisites for Using MapReduce

  • .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.
  • For API details, refer to: ICache, MapReduceTask, Combiner, Mapper, Reducer, ITrackableTask, GetResult, ITaskResult, IExecutionService, ExecuteTask, GetEnumerator.
  • 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.Runtime.Mapreduce namespace in your application.

The following example shows the sample usage of the MapReduce.

  • .NET
  • Legacy API
// Pre-condition: Cache is already connected

// Initialize MapReduce Task
MapReduceTask task = new MapReduceTask();

// Set Mapper, Combiner factory and Reducer factory
task.Mapper = new ProductCountMapper();
task.Combiner = new ProductCountCombinerFactory();
task.Reducer = new ProductCountReducerFactory();

// Execute task on cache
ITrackableTask wordCount = cache.ExecutionService.ExecuteTask(task, new ProductCountKeyFilter());

// Get result
ITaskResult result = wordCount.GetResult();

IDictionaryEnumerator enumResult = result.GetEnumerator();

while (enumResult.MoveNext())
{
    // Perform operations
}
//Initialize MapReduce Task
MapReduceTask task = new MapReduceTask();

//Set Mapper, Combiner factory and Reducer factory. Add filters, if required
task.Mapper = new WordCountMapper();
task.Combiner = new WordCountCombinerFactory();
task.Reducer = new WordCountReducerFactory();

//Execute task on cache
ITrackableTask wordCount = cache.ExecuteTask(task);

//Optional: enumerate over the result generated using enumeration.
ITaskResult result = wordCount.GetResult();

IDictionaryEnumerator enumResult = result.GetEnumerator();
while (enumResult.MoveNext())
{
   //perform operations
}
Note

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

Warning

This feature is only supported till 5.3 SP4.

See Also

Sample Implementation of MapReduce
Aggregator
Entry Processor
Configure MapReduce

In This Article
  • Prerequisites for Using MapReduce
  • 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