• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Server-side API Programming
  • Custom Dependency
  • Implement Notify Extensible Dependency
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 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
      • Overview
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Topics
      • Publish Messages
      • Subscribe to a Topic
      • Pub/Sub Events
      • Monitoring Topic Statistics
    • 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

Notify Extensible Database Dependency Usage and Implementation [Deprecated]

In addition to Bulk Extensible Dependency, NCache provides another method for cache dependency called Notification Based Extensible Dependency or Notify Extensible Database Dependency. In Notify Extensible Database Dependency, the client side is responsible for deploying a provider that holds the logic behind the dependency and when to invoke that dependency.

Note

This feature is only available in the NCache Enterprise for .NET Servers.

The server then invokes the cache for database dependency-related methods considering the logic provided by the client. The cache checks for items under Notify Extensible Dependency and whether they need to be removed or not.

In Notification-Based Extensible Dependency, clients have all the control over when and how to call a dependency on an item. In this way, items can be expired from the cache in an extremely flexible way. NCache provides an abstract class NotifyExtensibleDependency, an extension of custom dependencies provided by NCache, that implements this behavior.

Tip

Refer to Custom Cache Dependencies to get acquainted with all cache dependency custom methods provided by NCache.

Prerequisites

  • .NET
  • 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 project must be implemented as a Class Library (.dll) in Visual Studio. This will be deployed on NCache cluster.
  • Make sure to Deploy Custom Dependency Providers using the NCache Management Center.
  • The NotifyExtensibleDependency class must be deployed on cache
  • For API details, refer to: ICache, CacheItem, Add, insert, Remove, CustomDependency, CreateDependency, ICustomDependencyProvider, NotifyExtensibleDependency, DependencyChangedHandler.
Note

To get detailed information about the methods implemented in NotifyExtensibleDependency, refer to the Methods section.

Step 1: Implement NotifyExtensibleDependency Class

The first step in introducing your own logic for Notify Extensible Dependency is to inherit the NotifyExtensibleDependency class.

Let's suppose you want to add customers to your Cosmos database with your own dependency logic. Here's how to implement Notification Extensible Dependency with Cosmos DB in your application.

[Serializable]
    public class NotificationDependency<T> : NotifyExtensibleDependency
    {
        // Class parameters

        public NotificationDependency(/* */)
        {
            // Assign values to class members
        }

        public override bool Initialize()
        {
            // Register dependency against key
            RegisterDependency(_key, this);
            return true;
        }

        public bool RegisterDependency(string key, NotifyExtensibleDependency dependency)
        {
            lock (this)
            {
                // Your logic here
                dependencies.Add(key, dependency);
            }
            return true;
        }

        public void OnFeedChange(params object[] args)
        {
            // Find the matching dependency and fire its DependencyChangedEvent
            var key = args[0];
            var notifyExtensibleDep = (dependencies[key] as NotifyExtensibleDependency);
            notifyExtensibleDep?.DependencyChanged.Invoke(this);

            // Remove the matched keys from cache
            lock (dependencies)
            {
                dependencies.Remove(key);
            }
        }

        protected override void DependencyDispose()
        {
            // Dispose off resources
        }
        // This class is to be deployed on NCache
    }

Step 2: Implement NotifyCustomDependencyProvider

To implement the Notify Extensible Dependency provider in your application, use the following code snippet.

public class NotifyCustomDependencyProvider : ICustomDependencyProvider
{
    private string cacheName;
    private string monitoredUri;
    private string authKey;
    private string databaseName;

    public void Init(IDictionary<string, string> parameters, string cacheName)
    {
        // Initialize cache and class parameters
    }

    public NotificationDependency CreateDependency(string key, IDictionary<string, string> dependencyParameters)
    {
        string customerId="";
        string monitoredCollection = "";
        string leaseCollection = "";

        if (dependencyParameters != null)
        {
            if (dependencyParameters.ContainsKey("Key"))
                customerId = dependencyParameters["Key"];

            if (dependencyParameters.ContainsKey("MonitoredCollectionName"))
                monitoredCollection = dependencyParameters["MonitoredCollectionName"];

            if (dependencyParameters.ContainsKey("LeaseCollectionName"))
                leaseCollection = dependencyParameters["LeaseCollectionName"];

            // Create notify extensible dependency
            NotificationDependency<Customer> cosmosDbDependency = new NotificationDependency<Customer>(customerId,
                monitoredUri, authKey, databaseName, monitoredCollection, databaseName, leaseCollection);
            return cosmosDbDependency;
        }
        else
        {
            // Dependency parameters not found
        }
    }
    public void Dispose ()
    {
        // Dispose off all resources
    }
}

Step 3: Deploy Implementation on Cache

Deploy this class and all other dependent assemblies on NCache by referring to Deploy Providers in the Administrator's Guide for help.

Step 4: Use Notification Extensible Dependency

Once Notification-Based Extensible Dependency has been implemented and deployed on the cache, it is ready to be used in your application. The following code shows how to add data using the Insert method with Notification Based Custom Dependency.

Note

In case of client cache, the user needs to explicitly deploy these assemblies on the client cache.

// Specify the connection credentials
string endPoint = ConfigurationManager.AppSettings["EndPoint"];
string authKey = ConfigurationManager.AppSettings["AuthKey"];
string monitoredCollection = ConfigurationManager.AppSettings["MonitoredCollection"];
string leaseCollection = ConfigurationManager.AppSettings["LeaseCollection"];
string databaseName = ConfigurationManager.AppSettings["DatabaseName"];
string providerName = ConfigurationManager.AppSettings["ProviderName"];

// Fetch a sample customer from the database
Customer customer = LoadCustomerFromDatabase(customerId);

// Specify the unique key of the item
string key = "Customer#" + customer.Id ;

// Create dictionary for dependency parameters
IDictionary<string, string> param = new Dictionary<string, string>();
param.Add("CustomerID", customer.Id);
param.Add("EndPOint", endPoint);
param.Add("AuthKey", authKey);
param.Add("MonitoredCollection", monitoredCollection);
param.Add("LeaseCollection", leaseCollection);
param.Add("DatabaseName", databaseName);

//Creating notification dependency
CustomDependency cosmosDbDependency = new CustomDependency(providerName, param);

// Create a cacheItem
var cacheItem = new CacheItem(customer);
cacheItem.Dependency = cosmosDbDependency;

// Add cacheItem to the cache with notification dependency
cache.Insert(key, cacheItem);

Methods

Initialize()

Every time an item is added to the cache, the Initialize method is called to check whether the cache has a secure connection with the data source or not. If this method returns true, it means that the cache can establish a secure connection with the data source. It then places the item in the key-value store and the dependency list of the cache until it needs to be removed.

But, in case this method returns false, it shows that the data source required to access and monitor data isn't available to the cache, hence, that item is removed from the cache. The initialize method is available for all extensible dependencies.

DependencyChanged()

After an item is successfully placed in the cache, there's a need to know how to invoke dependency on it. For this reason, a delegate DependencyChanged is used. A handler of this delegate is deployed on the cache. The client gets to control when to call this delegate and invoke dependency on an item. Whenever this delegate is called, it removes the item against which it was called from the cache.

Additional Resources

NCache provides sample application for Notification Extensible Dependency on GitHub.

See Also

.NET: Alachisoft.NCache.Runtime.Dependencies namespace.

In This Article
  • Prerequisites
  • Step 1: Implement NotifyExtensibleDependency Class
  • Step 2: Implement NotifyCustomDependencyProvider
  • Step 3: Deploy Implementation on Cache
  • Step 4: Use Notification Extensible Dependency
  • Methods
    • Initialize()
    • DependencyChanged()
  • 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