• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Client Side API Programming
  • Events
Show / Hide Table of Contents
  • Programmer's Guide
  • Setting Up Development Environment
    • .NET
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Java
      • Client API Prerequisites
      • Server-side 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 Server
      • Oracle
      • OleDB with Polling
      • 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
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Topics
      • Publish Messages
      • Subscribe to a Topic
      • Pub/Sub Events
    • 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
    • Clear Cache
    • 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
        • NCache Extension for SignalR Core
      • 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

Event Notifications in Cache: An Overview

In a distributed caching paradigm, your client application may need to get notified about the variety of operations happening in the cache. NCache can generate different types of events while your client applications can register for events of interest to get notified.

Note

This feature is only available in NCache Enterprise.

Here are some key points related to events in the cache:

  • An event is generated only if a client application has registered for it.
  • An event is published only to subscribed clients.
  • The cache determines when an event is raised and the client determines the action to be taken in response to an event.
  • A client can register for multiple events and can also handle multiple events from multiple caches.
Note

An application will not be able to receive events unless it registers itself against the cache using the specific event registration API call.

Importance of Event Notifications in Cache

Many applications today need to share data asynchronously with each other at runtime to provide data integrity. In addition, they need to update their state of data or synchronize the snapshot of data with the server-side state. Therefore, the application needs a mechanism to monitor its state of data with the server. Event Notifications provide this mechanism for notifying the client application every time data is changed in the cache.

Hence, events allow runtime data sharing among separate applications or separate modules of the same application. Moreover, event-driven data fetching supported by NCache enables client applications to receive data without any explicit data fetch request to the cache server.

Events in NCache

Events may be raised for cache-level activity specific to data or management operations. Here, we categorize events and discuss relevant details.

Data Specific Events

As the name indicates, these events are triggered when data in the cache is modified due to add, update, or remove operations. Aside from these basic CRUD operations, data-specific events are also fired when data is added, updated, or removed in cache due to Cache Startup Loader/Refresher and Backing Source.

To register these events for notification, the MessagingService.RegisterCacheNotification method is used. Similarly, data-specific notifications can be easily unregistered if no longer required, using the MessagingService.UnRegisterCacheNotification method.

You need to specify the appropriate EventType while registering for data-specific events using EventType enum. The following notifications can be fired based on registered EventType:

  • Add Notification: Add notification is triggered when the ItemAdded event type is registered and a new item is added to the cache.

  • Update Notification: Update notification is triggered when the ItemUpdated event type is registered and an existing item is updated in the cache.

  • Remove Notification: Remove notification is triggered when the ItemRemoved event type is registered and an item is removed from the cache.

You can also control the information returned upon an event execution using the EventDataFilter which is further discussed in the Event Filters section.

The data-specific events can be further categorized as follows:

Cache Level Events

The Cache Level Events are general events for cache which are triggered upon the execution of the Add, Update, or Remove operations on cache data. The purpose is to notify different clients about every operation performed on the cache.

Warning

The Cache Level Events might degrade your application performance when notifications are registered for all operations on the entire cache data set.

By default, the Cache Level Events are disabled (except for cache cleared operation) for any cache configuration and must be enabled for events to be published using the NCache Management Center.

Item Level Events

The Item Level Events can be useful when you want to be notified about a limited set of data rather than every operation performed on the cache. For example, if the cache contains a large amount of data and gets notified every time any change occurs in the data set, it causes overhead and the application performance gets affected.

Note

For better performance, you can register notifications for the data set of interest only.

The cache will be responsible for monitoring changes for the specified keys. Since the selected data set already exists in the cache, the Item Level Events are received on the update or remove operation only. Applications register callback methods for a specific key in the cache using API calls and get a notification when that key gets updated or removed from the cache. These notifications are asynchronously sent to the client so there is no overhead on the client’s activities.

Note

Since the Item Level Events are registered for data set already in the cache, add notification can not be received.

Management Level Events

The Management Level Events are useful when you want to be notified about any management operation that is performed on the cache cluster using the NotificationService interface.

These events can be used for validation to see if operations continue on the cache or not. For example, the client is a multi-threaded application where a thread is dedicated to inserting items at a constant rate. If the cache is stopped during insertion, the NCache client will throw OperationFailedException. To prevent the exception from being thrown, the thread must take appropriate action upon stopping of cache. This can be simply achieved by registering for an event against cache stop action.

This example also applies to cache clear notifications if the client application’s thread validates operations during its execution while the cache is cleared. All validations will fail if the client application does not consider a clear cache event.

The following notifications are fired when management operations are performed on the cache:

  • Cache Cleared Notification: Cache cleared notification is fired when the cache is cleared.

  • Cache Stopped Notification: Cache stopped notification is fired when cache is stopped. If an application continues to perform operations when the cache is stopped without knowing that the cache is stopped, an exception will be thrown for the operations performed.

  • Member Joined Notification: Member joined notification is fired when a member joins the cluster. A cache administrator or a user monitoring the state of the cache during operations could automate their tasks for monitoring the state of the cluster. Hence, if a member joins the cluster, the event should be handled to prevent any interruption in the automated tasks.

  • Member Left Notification: Member left notification is fired when a member leaves the cluster.

Client Activity Events

Client activity events notify the connection/disconnection of clients. Each client connected to a clustered cache can subscribe to these events to get notified about the connect/disconnect events of other clients.

You can also specify the Retention Period, which is the time after which a disconnected client is considered disconnected, and its disconnect event is fired. If a client reconnects within the retention period, its disconnect event is not fired.

This is to compensate for any accidental disconnects occurring due to buggy networks since the NCache client automatically reconnects in such networks without disrupting the client operations. Note that this does not apply to the clients that manually dispose and reinitialize themselves.

You need to enable client activity notifications in the NCache Management Center before use.

Event Data Filters

NCache provides the EventDataFilter to control the amount of information returned upon execution of data-specific events. The types of event filters are explained below.

Warning

The event data filter must be carefully set to avoid unnecessary network bandwidth consumption.

None

This filter returns only the keys affected by the operation in the event notification. This is used if the application is only interested in knowing which keys were affected. For instance, an e-commerce site wants to know which product keys were added and not the values themselves.

Metadata

With this filter, the affected keys along with their metadata are returned in the event notification. The metadata that is returned includes the group, cache item priority, expiration, CacheItemVersion, ResyncOptions, CacheItemRemovedReason, and EntryType. This information may be required by the user. For instance, when an application wants to know which keys were removed from the cache and which groups they belonged to.

DataWithMetadata

This filter returns the keys along with the cached items and their associated metadata. This can be used in cases when an application needs to process the modified data. For instance, a banking application might require knowing which customer's information has been modified. Hence, it can register notifications for item update operations with this filter so that the item key and modified item are also returned to the user once the event is fired.

Using the DataWithMetadata filter saves a trip when fetching items again with the Get API. However, this filter must be used where necessary, since it may cause network hogging when the amount of data returned is huge.

Warning

In case of client disconnection, the events are not logged during the disconnected time span of the client.

Topology Wise Behavior

Event notifications are fired according to the cache topology being used. The topology-wise behavior for event notifications is described as follows:

  • Mirror Topology: In the Mirror Topology, an active node of the cluster is responsible for notifying the event to the client.

  • Replicated Topology: In the Replicated Topology, the node in the cluster that is connected to the client is responsible for raising the event notifications.

  • Partition-Replica Topology: In the Partition-Replica Topology, events are fired from the active nodes. The node where criteria-based data resides is responsible for event notifications.

  • Partitioned Topology: In the Partitioned Topology, events are fired from all nodes. The node where criteria-based data resides is responsible for event notifications.

In This Section

Cache Level Events
Explains how to use notification mechanism for events occurring at cache level.

Item Level Events
Explains how to use notification mechanism for events occurring at item level.

Management Level Events
Explains how to add management level events mechanism.

In This Article
  • Importance of Event Notifications in Cache
  • Events in NCache
    • Data Specific Events
    • Management Level Events
    • Client Activity Events
  • Event Data Filters
    • None
    • Metadata
    • DataWithMetadata
  • Topology Wise Behavior
  • In This Section

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