NCache as IDistributed Cache provider for ASP.NET Core applications

The older ASP.NET framework provided ASP.NET Cache that was stand-alone and therefore didn’t meet the needs of multi-server environments. It also didn’t allow any “custom” third-party cache providers to plug-in so you were stuck with its built-in stand-alone InProc implementation.

Now, the new ASP.NET Core has fixed that problem and by introducing IDistributedCache interface to handle caching in a multi-server environment (e.g. load balanced web farms). Here is what IDistributedCache interface looks like (please note that each of these methods also has an Async overload).

namespace Microsoft.Extensions.Caching.Distributed
{
    public interface IDistributedCache
    {
        // These methods also have overloads for “Async”
        byte[] Get(string key);
        void Refresh(string key);
        void Remove(string key);
   
        // Absolute expiration & sliding expirations possible
        void Set(string key, byte[] value,
            DistributedCacheEntryOptions options);
    }
}

Additionally, ASP.NET Core IDistributedCache interface is pluggable by design and allows you to use third-party providers of your choice. NCache has implemented a provider for IDistributedCache that you can plug in to your ASP.NET Core applications seamlessly. This way, you don’t have to change any code specific to NCache.

Configure NCache as IDistributedCache Provider

And, here is how to configure NCache as your IDistributed Cache provider in your ASP.NET Core Startup class:


public class Startup {
     ...
        public void ConfigureServices (IServiceCollection services) {
            ...
            services.AddNCacheDistributedCache();
            ...
        }
        ...
}

NCache API Far Richer than IDistributedCache

It gives you a lot of flexibility to program against IDistributedCache interface because you can now plug in any third party distributed cache of your choice. However, that flexibility comes at a cost that IDistributedCache interface is very simple and basic. As a result, you are unable to benefit from some very important distributed caching features.

If you put in a little bit of extra effort up front and use NCache API directly, you benefit greatly from a vast variety of NCache advanced caching features including:

  • Search Cache with SQL Queries
  • Sync Cache with Database
  • Managing Data Relationships in the Cache
  • Pub/Sub Messaging
  • Data Grouping
  • Read-through and Write-through
  • Entity Framework Core Caching
  • Much More…

Learn more about all the NCache features that are useful to you.

NCache a Better Choice than Redis for .NET Apps

NCache is a much better choice than Redis for .NET apps for the following reasons:

  • NCache Native .NET: NCache is 100% .NET / .NET Core and therefore fits into your .NET application stack very nicely. On the other hand, Redis comes from a Linux background and is not a native .NET cache that complicates your overall development, QA, and production environments.
  • Faster than Redis: NCache is actually faster than Redis. On regular features, NCache and Redis have approximately the same performance. But, NCache has this Client Cache feature that gives NCache a significant performance boost over Redis.
  • More Features than Redis: NCache offers a variety of very important distributed cache features that Redis does not. This includes (see NCache vs Redis detailed comparison for more details):
    • Search Cache with SQL Queries
    • Sync Cache with Database
    • Managing Data Relationships in the Cache
    • Data Grouping
    • Read-through and Write-through
    • Entity Framework Core Caching
    • More…

What to Do Next?

NCache comes in the following three editions:
NCache Open Source
NCache Professional
NCache Enterprise

For more details about each edition, see Edition Comparison. Or, chose one of the following options below.

Signup for monthly email newsletter to get latest updates.

© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.