Cookie Consent by Free Privacy Policy Generator IDistributedCache Provider for ASP.NET Core - NCache

IDistributedCache Provider for ASP.NET Core

Enhance Your ASP.NET Apps

The traditional ASP.NET framework relied on the ASP.NET Cache, which was limited to a single server (InProc) and lacked support for multi-server environments. It also didn't allow integration with third-party distributed caches. As a result, developers were forced to rely on inefficient, standalone caching mechanisms.

Microsoft solved these challenges with ASP.NET Core, introducing the IDistributedCache, interface for scalable, multi-server caching solutions. NCache is easy to integrate with IDistributedCache, which gives your ASP.NET Core applications a high-performance, feature-rich caching layer.

 

What is IDistributedCache?

The IDistributedCache interface provides a centralized caching mechanism that works across multiple servers, making it ideal for cloud-native, containerized, and microservice-based architectures. While the standard interface defines the contract, NCache provides the actual distributed implementation that ensures data persists across server restarts and scales linearly with traffic.

using Microsoft.Extensions.Caching.Distributed;
using System.Threading;
using System.Threading.Tasks;

public interface IDistributedCache
{
    byte[]? Get(string key);
    Task<byte[]?> GetAsync(string key, CancellationToken token = default);
    void Refresh(string key);
    Task RefreshAsync(string key, CancellationToken token = default);
    void Remove(string key);
    Task RemoveAsync(string key, CancellationToken token = default);
    void Set(string key, byte[] value, DistributedCacheEntryOptions options);
    Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = default);
}
 

Why Choose NCache for IDistributedCache?

Many caching solutions, like MemoryDistributedCache, are limited to a single server, making them unsuitable for applications that need scalability and high availability. NCache, on the other hand, is a true distributed caching solution designed specifically for .NET applications, ensuring better performance and scalability.

Key Benefits of NCache

  • 100% Native .NET - Fully compatible and optimized for .NET applications.
  • High Performance & Scalability - Enables fast data retrieval and supports seamless horizontal scalability.
  • Advanced Caching Features - Supports SQL queries, pub/sub messaging, and cache synchronization.
  • High Availability & Reliability - Ensures data consistency with built-in failover support.
  • Optimized Serialization - Reduces latency and improves performance through efficient serialization.

Seamless NCache Integration with IDistributedCache

Integrating NCache with your ASP.NET Core application is simple. You can plug-in NCache without modifying existing application logic. This allows you to transition smoothly from in-memory caching to a highly available distributed cache.

 

Configure NCache as Your IDistributedCache Provider

  • Step 1: Install the NuGet Package Run the following command in your Package Manager Console to install the IDistributedCache provider.
    Install-Package Alachisoft.NCache.DistributedCache
  • Step 2: Register NCache in Program.cs Register NCache in the ASP.NET Core application's startup file as shown below:
var builder = WebApplication.CreateBuilder(args);
// Register NCache as the IDistributedCache provider
// Benefits: Multi-server scalability, High Availability, and 100% Native .NET

builder.Services.AddNCacheDistributedCache(options =>
{
    options.CacheName = builder.Configuration["NCache:CacheName"];
	 
   // NCache settings can be dynamically adjusted in appsettings.json
   // ensuring zero-downtime configuration changes
});

var app = builder.Build();
app.MapControllers();
app.Run();

Alternatively, you can configure NCache in the appsettings.json file and load settings dynamically:

{
    "NCacheSettings": {
        "CacheName": "myCache",
        "EnableLogs": true,
        "EnableStatistics": true
    }
}

This ensures scalability, fault tolerance, and high availability in production environments.

 

NCache API: Far Richer than IDistributedCache

The IDistributedCache interface provides a basic key-value store, which is useful but quite limited in functionality. NCache goes far beyond by offering an extensive, high-performance caching API that enables powerful, distributed caching for enterprise applications.

Feature Standard IDistributedCache (Basic) NCache API (Enterprise)
Query Flexibility Key-value lookup only SQL & LINQ Queries
Data Organization Flat structure Tags & Named Tags
Data Integrity Independent items Cache Dependencies (Relationships)
Real-time Messaging Not supported Pub/Sub Messaging
Database Sync Manual coding required Auto Read-Through & Write-Through
Data Availability Empty on startup Cache Loader & Refresher
 

Key Advantages of NCache API

By using the NCache API, organizations can overcome the limitations of IDistributedCache, unlocking enhanced performance, flexibility, and enterprise-grade caching for their .NET applications.

 

Get Started with NCache Today!

Ready to optimize your ASP.NET Core applications with high-performance distributed caching? Explore NCache and take advantage of its powerful features.

Frequently Asked Questions (FAQ)

No. Since NCache implements the standard IDistributedCache interface, you only need to change the configuration in Program.cs. No business logic changes are required.

NCache stores data in-memory (RAM), which is significantly faster than SQL Server's disk-based storage. It also eliminates the serialization overhead and network latency associated with SQL-based caching.

Yes. You can continue using standard methods like SetAsync, GetAsync, and RemoveAsync. However, NCache also allows you to cast the cache instance to ICache to unlock advanced features like Tags and SQL Queries.

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