• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Third-Party Wrappers
  • AppFabric to NCache Migration
  • AppFabric API vs. NCache API
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

AppFabric Cache API vs. NCache API

Given that AppFabric is an obsolete technology, there are many differences between both of them. For instance, AppFabric Cache uses regions to define divisions in the caches. Regions in AppFabric Cache are logical collections for organizing and managing cached data. On the other hand, NCache, uses Tags to symbolize them. Tags are string-based identifiers that let you associate keyword(s) with your cache items to create a logical collection.

For example, if you add the string "key1" in the default cache in AppFabric, you can also add "key1" in a region created by you in the same cache. For NCache, you can use a tag with the cache item "key1" to simulate a region. Similarly, NCache is adept at overcoming such differences.

AppFabric Cache: Getting Cache Instance

In the AppFabric Cache, the user has to create a DataCacheFactoryConfiguration that supplies a DataCacheFactory, and from this, they can get a cache instance. In NCache, the configurations are taken care of by the NCache Management Centre or the Command Line Tool. The following command will return an instance of the cache if it is running and initialized.

ICache cacheInstance = CacheManager.GetCache(cacheName);

There are many cache management functions available in this instance. This section compares some of the overloads of the APIs to get a brief idea of how things are different with NCache.

Note

Your application will fetch the cache name from the client.ncconf file, therefore, please ensure that it is present as a part of your deployment. If you do not have NCache installed on your client machine, you can use the client.ncconf file added to your application project when you install the NCache AppFabric wrapper NuGet package to configure the cache client to access the NCache cluster. If you have NCache installed on your machine, you can find this file at %NCHOME%\config.

CRUD Operations

Add Operation

  • AppFabric
  • NCache

In AppFabric Cache, an Add operation is as follows:

cacheInstance.Add(stringKey, stringValue);

In NCache, the basic command is not different, but when you are specifying a region in the command you must do the following:

cacheInstance.Add(stringKey, stringValue, regionName);

In this case, use the following command to achieve the same functionality as a region:

regionNameasCacheInstance.Add(stringKey, stringValue);

You have to register the region as a tag in NCache. Otherwise, you will not be able to use the above command.

Get Operation

The AppFabric and NCache Get operations are the same in syntax.

// Retrieve object
Object object = cache.Get<Object>(key);

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

Put/Insert Operation

The AppFabric Put operation is equivalent to NCache's Insert method. The simplest overload for both NCache and AppFabric is the same:

  • AppFabric
  • NCache
cacheInstance.Put(key, value);
cacheInstance.Insert(key, value);

Remove Operation

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

  • AppFabric
  • NCache
cacheInstance.Remove(key, dataCacheItemVersion);

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

cacheInstance.Remove(key, cacheItemVersion);

cacheInstance.Delete(key, cacheItemVersion);

Further Get Operations

Bulk Get Operation

  • AppFabric
  • NCache

AppFabric has the following command to get multiple entries in the cache, returning a List KeyValuePair.

cacheInstance.BulkGet(listOfKeys, region);

In NCache, the Bulk command returns an IDictionary of <string, object> pair:

cacheInstance.GetBulk<T>(keys);

The argument type differs for both APIs as AppFabric requires a List, whereas NCache requires an Array.

GetIfNewer Operation

The GetIfNewer operations for AppFabric and NCache are the same.

GetObjectsByAllTags

  • AppFabric
  • NCache

AppFabric returns a list of KeyValuePair<string, object> and takes a list of DataCacheTag items to fetch the items added to the cache with the corresponding tags.

cacheInstance.GetObjectsByAllTags(listOfDataCacheTag, region);

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.

cacheInstance.GetByAllTags(arrayofTag);

GetObjectsByAnyTag Operation

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

GetObjectsByTag

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

GetObjectsInRegion

As mentioned earlier, NCache uses tags to represent regions. Therefore, to get all the objects in a region, NCache returns an enumerator, which you can iterate to get the key-value pairs present in the cache.

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

Locking and Unlocking Operations

GetAndLock Operation

  • AppFabric
  • NCache

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

cacheInstance.GetAndLock(key, timeout, out lockHandle);

For NCache, the same command is as follows:

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

PutAndUnlock Operation

  • AppFabric
  • NCache

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. NCache achieves this 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 an argument which allows the user to add Tags directly to the item along with 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 a richer CacheItem to have an item in the cache that holds more metadata, which helps keep everything organized and structured.

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 items.

  • AppFabric
  • NCache
cacheInstance.Unlock(key, dataCacheLockHandle);
cacheInstance.Unlock(key, lockHandle);

ResetObjectTimeout Operation

  • AppFabric
  • NCache

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

cacheInstance.ResetObjecTimeout(key, newTimeout)

In NCache, the client can accomplish the same behavior by inserting the same value with a new Absolute Expiration:

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

This approach may seem more tedious when trying to maintain the value associated with the key at the client end. NCache provides a better alternative. The client can simply add the item with a Sliding Expiration. This is just like the expiration in AppFabric, but when an item is updated or fetched from the cache, its timeout is automatically reset. Therefore, the need for managing the timeouts of the objects is handled by NCache, making the user's job easier.

CallBack Registration

AppFabric allows the client to register event notifications on the cache and item levels. NCache provides a similar functionality. The difference occurs in the layout of the delegate used for either.

  • AppFabric
  • NCache
public delegate void DataCacheNotificationCallback(string cacheName, string regionName, string key, DataCacheItemVersion version, DataCacheOperations cacheOperation, DataCacheNotificationDescriptor nd);
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 metadata, and any other information for which the user has registered the event.

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

  • AppFabric
  • NCache
cacheInstance.AddCacheLevelCallback(dataCacheOperations, dataCacheNotificationCallback);
cacheInstance.RegisterCacheDataNotification(cacheDataNotificationCallback, eventType, EventDataFilter.DataWithMetaData);

As you can see, NCache provides a more comprehensive mechanism for registering 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 lets the user 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 a single item.

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

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

See Also

.NET: Alachisoft.NCache.Client namespace.
Java: com.alachisoft.ncache.client namespace.
Node.js: Cache class.
Python: ncache.client class.

In This Article
  • AppFabric Cache: Getting Cache Instance
  • CRUD Operations
    • Add Operation
    • Get Operation
    • Put/Insert Operation
    • Remove Operation
  • Further Get Operations
    • Bulk Get Operation
    • GetIfNewer Operation
    • GetObjectsByAllTags
    • GetObjectsByAnyTag Operation
    • GetObjectsByTag
    • GetObjectsInRegion
  • Locking and Unlocking Operations
    • GetAndLock Operation
    • PutAndUnlock Operation
    • Unlock Operation
  • ResetObjectTimeout Operation
  • CallBack Registration
  • 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