• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Show / Hide Table of Contents
  • Programmer's Guide
  • Client Side API Programming
    • Setting Up Development Environment
    • Basic Cache Operations
      • Initialize Cache
      • Add Data to Cache
      • Update Data in Cache
      • Fetch Data From Cache
      • Remove Data From Cache
      • Dispose Cache
    • Bulk Operations
      • Adding Collection to Cache
      • Updating Collection in Cache
      • Retrieving Collection from Cache
      • Removing Collection from Cache
      • Deleting Collection from Cache
    • Asynchronous Operations
      • Using Asynchronous Operations
      • Using Asynchronous Operations with Callback Methods
    • Groups and Subgroups
      • Adding/Updating Data Group in Cache
      • Retrieving Data Group from Cache
      • Removing Data Group from Cache
    • Tagging Data in NCache
      • Creating Tags
      • Adding Items with Tags
      • Retrieving Previously Tagged Data
      • Removing Tagged Items from Cache
    • Named Tags
    • Data Expiration Strategies
      • Using Absolute Expiration
      • Using Sliding Expiration
    • Cache Dependencies
      • Key Dependency
      • File Dependency
      • Notification based Dependencies
        • Database Dependency using SQL Server
        • Database Dependency using Oracle
      • Polling Based Dependency
      • Custom Data Source Dependency
      • Multiple Cache Sync Dependency
      • Aggregate Dependency
      • Add Dependency to Existing Item
      • Using CLR Procedures to Call NCache
    • Locking Data in NCache
      • Locking Items in Cache (Pessimistic Locking)
      • Locking Items with Cache Item Versioning (Optimistic Locking)
    • SQL Reference for NCache
      • SQL Syntax
      • Querying Samples for Operators
      • Querying Data in NCache
      • NCache Language Integrated Query (LINQ)
        • Using LINQ in NCache
        • Configuring LINQPad for NCache
        • Querying NCache Data in LINQPad
    • Event Notifications
      • Cache Level Event Notifications
      • Item Level Event Notifications
      • Custom Event Notifications
    • Publish/Subscribe (Pub/Sub) in NCache
      • Pub/Sub Topics
      • Managing Topics
      • Pub/Sub Messages
        • Message Behavior and Properties
        • Creating a Message
      • Publish Messages to Topic
      • Subscribe for Topic Messages
      • Monitoring Pub/Sub Topics
    • Continuous Query
    • Using Streams in NCache
      • Opening with Stream Modes
      • Adding and Updating Data with Streams
      • Retrieving Data from Streams
      • Closing a Stream
    • Security and Encryption
      • NCache Security
      • NCache Data Encryption
    • Data Compression
    • NCache Management API
  • Server Side API Programming
    • Cache Startup Loader
      • Components of Cache Startup Loader
      • Sample Implementation of ICacheLoader on Single Node
      • Sample Implementation of ICacheLoader with Distribution Hints
    • Data Source Providers (Backing Source)
      • Read-Through Caching
        • Configure Read-Through Provider
        • Using Read-Through with Cache Operations
      • Write-Through Caching
        • Configuring Write-Through Provider
        • Using Write-Through with Basic Operations
        • Using Write-Behind with Basic Operations
        • Using Write-Behind with Bulk Operations
        • Using Write-Behind with Async Operations
        • Monitor Write-Through Counters
    • Custom Dependency
      • Sample Implementation of Custom Dependency
      • Sample Usage of Custom Dependency
    • WAN Replication through Bridge
      • Bridge Configurations
      • Implementing Bridge Conflict Resolver
    • Entry Processor
      • Sample Implementation of IEntryProcessor Interface
      • Sample Usage of EntryProcessor
    • MapReduce
      • Sample Implementation of MapReduce Interfaces
      • Sample Usage of MapReduce
    • Aggregator
      • Sample Implementation of IValueExtractor Interface
      • Sample Implementation of IAggregator Interface
      • Sample Usage of Aggregator
    • Dynamic Compact Serialization
  • Client Side ASP.NET Features
    • ASP.NET
      • ASP.NET Session State Provider for NCache
      • Multi-Region ASP.NET Session State Provider for NCache
    • ASP.NET Core
      • Session Storage in ASP.NET Core
        • Configure NCache ASP.NET Core Session Provider
        • Configure ASP.NET Core Sessions with NCache IDistributedCache Provider
      • Multi-Region ASP.NET Core Session Provider for NCache
      • Object Caching in ASP.NET Core
    • ASP.NET SignalR
      • Using NCache Extension for SignalR
    • View State Caching
      • Configuring and Using Content Optimization
      • Group View State with Sessions
      • Limit View State Caching
      • Perform Page Level Grouping for View State
    • ASP.NET Output Cache
      • Configure ASP.NET Output Caching
      • Using ASP.NET Output Cache with Custom Hooks
  • Client Side Third Party Integrations
    • Migrating AppFabric to NCache
      • AppFabric API vs. NCache API
    • NHibernate
      • NCache as NHibernate Second Level Cache
      • Using NHibernate Query Caching
      • Configuring Database Synchronization with NHibernate
    • Entity Framework Caching Integration
      • NCache as Entity Framework Second Level Cache
      • Entity Framework Caching Config File
    • Entity Framework Core Caching
      • Installing NCache Entity Framework Core Provider
      • Configuring NCache Entity Framework Core Provider
      • Using NCache Entity Framework Core Provider
        • Caching Options for EF Core Provider
        • LINQ APIs for EF Core Provider
        • Cache Only APIs for EF Core Provider
        • Query Deferred APIs for EF Core Provider
      • Logging in NCache Entity Framework Core Provider
    • Memcached
      • NCache Memcached Gateway Approach
      • Memcached Client Plugin for .NET
    • Debug NCache Providers in Visual Studio
    • NCache for Visual Studio Extension

NCache API vs. AppFabric API

AppFabric uses regions to define divisions in the caches. NCache uses caches to symbolize them. As regions reside in a named cache and can have same yet unique keys, NCache uses caches to mimic this behavior.

For example, you add "key1" with a string value in the default cache in AppFabric. Now you can also add "key1" in a region created by you in the SAME cache. For NCache key is unique in a cache so in order to use multiple regions, multiple caches must be created.

Getting Cache Instance

In AppFabric the user has to create a DataCacheFactoryConfiguration which needs to be supplied to a DataCacheFactory and from this factory object the user can get a cache instance. In NCache, the configurations are taken care of by the Manager or the command line tool and the following command will return an instance of the cache if it is running and initialized.

NCache.Web.Caching.NCache.InitializeCache(cacheName);

There are many cache management functions available through this instance. We are going to compare some of the overloads of the APIs to get a brief idea of how things are different with NCache.

Add Operation

In AppFabric a basic Add operation looks like the following:

cacheInstance.Add(stringKey, stringValue);

In NCache the basic command is no different but when you are specifying a region in the command like:

cacheInstance.Add(stringKey, stringValue, regionName);

In this case to achieve the same functionality as of a region the following command must be used:

regionNameasCacheInstance.Add(stringKey, stringValue);

You have to register the region as a cache in NCache otherwise you will not be able to use the above command.

Bulk Get Operation

AppFabric has the following command in order to get multiple entries residing in the cache.

cacheInstance.BulkGet(listOfKeys, region);

This returns a List KeyValuePair in AppFabric whereas in NCache the Bulk command returns an IDictionary of <string, object> pair:

cacheInstance.GetBulk(arrayOfKeys);

The argument type is also different for both APIs as AppFabric requires a List whereas NCache required an Array.

Get Operation

AppFabric Get operation and NCache Get operation are the same in syntax.

GetAndLock Operation

AppFabric GetAndLock operation is synonymous to the overload of Get operation of NCache which takes a reference of LockHandle as an argument. For AppFabric a command looks like:

cacheInstance.GetAndLock(key, timeout, out lockHandle)

For NCache the same command is as follows:

cacheInstance.Get(key, timeout, ref this.lockHandle)

Both commands return an object as the value associated with the key.

GetCacheItem Operation

The GetCacheItem command for both AppFabric and NCache is the same with NCache having multiple overloads to filter the CacheItem returned.

GetIfNewer Operation

The GetIfNewer operation for AppFabric and NCache are exactly the same.

GetObjects Operation

GetObjectsByAllTags

AppFabric returns a list of KeyValuePair<string, object> and takes a list of DataCacheTag items to fetch the items that were added to the cache with the corresponding tags. NCache has the GetByAllTags command to substitute this functionality. For NCache a Hashtable is returned and the function takes an array of Tags as an argument.

AppFabric:

cacheInstance.GetObjectsByAllTags(listOfDataCacheTag, region)

NCache:

cacheInstance.GetByAllTags(arrayofTag)

GetObjectsByAnyTag Operation

Same as above, the GetObjectsByAnyTag returns a list in case of AppFabric and a Hashtable in the case of NCache.

GetObjectsByTag

This operation takes a single DataCacheTag in case of AppFabric and a Tag in case of NCache.

GetObjectsInRegion

As mentioned earlier NCache uses caches to represent region therefore in order to get all the objects present in a region/cache NCache can return an enumerator which you can iterate over to get the key value pairs present in the cache.

Put Operation

AppFabric Put operation can be replaced with NCache's Insert method. The simplest overload for both NCache and AppFabric is the same:

AppFabric:

cacheInstance.Put(key, value)

NCache:

cacheInstance.Insert(key, value)

In case of AppFabric a DataCacheItemVersion is returned whereas in case of NCache CacheItemVersion is returned which are essentially the same (See documentation).

PutAndUnlock Operation

AppFabric provides this functionality in one function where a locked item is unlocked and updated in the cache. The item can be updated with new DataCacheTags as well. In NCache the updating after unlocking the item is achieved by using an overload of the Insert function. A simple AppFabric command will look like the following in which the item is inserted with DataCacheTags.

cacheInstance.PutAndUnlock(key, value, lockHandle, dataCacheTags);

NCache takes CacheItem as argument which allows the user to add Tags directly to the item along with Group. Sub-Group, Expiration and Dependencies. The NCache overload is rich and provides more customizability.

cacheInstance.Insert(key, cacheItem, lockHandle, acquireLockBool)

Unlike AppFabric which takes an object as the new value for the key, NCache provides the more rich CacheItem to have an item in the cache that holds more metadata that helps on forming organized and structured data groups.

Remove Operation

AppFabric and NCache have similar Remove operations except for the return type. In case of AppFabric, the return type of a Remove function is Boolean which signifies whether the item is successfully removed or not. In NCache, the return type is object, which is to say the value of the object associated with the said removed key. This functionality of NCache is similar to getting the item and deleting it from cache.

cacheInstance.Remove(key, dataCacheItemVersion)

In NCache you can use either Remove or Delete. If the client simply wants to delete the item without fetching the item, NCache provides the Delete functionality.

cacheInstance.Remove(key, cacheItemVersion)

cacheInstance.Delete(key, cacheItemVersion)

ResetObjectTimeout Operation

AppFabric provides the functionality of resetting the expiration time of the item present in cache by using the following function:

cacheInstance.ResetObjecTimeout(key, newTimeout)

In NCache the client can accomplish the same behavior by inserting the same item with the same value with a new absolute expiration:

cacheInstance.Insert(key, value, absoluteExpiration, null,
CacheItemPriority.Default)

This may seem more tedious as to maintain the value associated with the key at the client end would require more resources. NCache provides a better alternative. The client can simply add the item with Sliding expiration. This is just like the expiration used in AppFabric but when an item is updated or fetched from the cache the timeout is automatically reset for the key. Therefore, the need for managing the timeouts of the objects is handled by NCache making the clients job less hectic.

Unlock Operation

AppFabric and NCache share the same functionality when it comes to unlocking an item present in the cache. Both use a key and a lock handle object to unlock the respective item.

AppFabric:

cacheInstance.Unlock(key, dataCacheLockHadle)

NCache:

cacheInstance.Unlock(key, lockHandle)

CallBack Registration

AppFabric allows the client to register event notification on cache and item level. NCache provides a similar behavior. The difference comes in the layout of the delegate used for either.

AppFabric:

public delegate void DataCacheNotificationCallback(string cacheName, string
regionName, string key, DataCacheItemVersion version, DataCacheOperations
cacheOperation, DataCacheNotificationDescriptor nd);

NCache:

public delegate void CacheDataNotificationCallback(string key, CacheEventArg
cacheEventArgs);

The AppFabric delegate is verbose whereas NCache is concise and to the point. The CacheEventArg class contains all the required values such as the value associated with the key, the meta data and any other information for which the client has registered the event for.

Registering a cache level callback is defined for each as follows:

AppFabric:

cacheInstance.AddCacheLevelCallback( dataCacheOperations,
dataCacheNotificationCallback)

NCache:

cacheInstance.RegisterCacheDataNotification( cacheDataNotificationCallback,
eventType, EventDataFilter.DataWithMetaData)

As you can see NCache provides a more comprehensive mechanism to register a notification callback. Also, note here that AppFabric allows one callback to be registered for only ONE kind of event meaning you can have one callback for Item added and another for Item updated. NCache allows the client to add a single callback with multiple types of events like the following modified command from above:

cacheInstance.RegisterCacheDataNotification( cacheDataNotificationCallback,
EventType.ItemAdded | EventType.ItemUpdated, EventDataFilter.DataWithMetaData)

NCache also provides multiple callbacks to be registered for single item.

NCache, however, does not provide alternatives to certain events supported by AppFabric such as failure notification callback in a failed operation triggers an event and user delegate's code is executed.

However, the client can find ways to mimic the same behavior by using the extensive functionality provided by NCache.

Back to top Copyright © 2017 Alachisoft