ASP.NET Core Response Cache Middleware

ASP.NET Core is quickly becoming popular for developing high traffic web applications. And, these web applications need to provide fast response times even during peak loads. And, to achieve that, among other things, these applications rely on ASP.NET Core Response Cache Middleware. This middleware determines when responses are cacheable, stores responses in NCache, and serves responses from the cache.

NCache has implemented ASP.NET Core Response Cache Middleware for applications running in load-balanced multi-server web farms. NCache is an extremely fast and scalable In-Memory Distributed Cache for .NET / .NET Core.

Using NCache as Response Cache Middleware

You can configure your ASP.NET Core application to use NCache as your Response Cache Middleware. This is particularly very useful if your ASP.NET Core application is running in a load-balanced multi-server environment.

Using NCache as your Response Cache Middleware is very straight forward. Here is what you do in your ASP.NET Core application.


  public void ConfigureServices(IServiceCollection services)
  {
	  services.Configure<CookiePolicyOptions>(options =>
  	  {
		  options.CheckConsentNeeded = context => true;
		  options.MinimumSameSitePolicy = SameSiteMode.None;
	  });

	  services.AddResponseCaching();
	  services.AddNCacheDistributedCache(Configuration.GetSection("NCacheSettings"));

	  services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  }

The two lines above configure your ASP.NET Core application to start using NCache as the Response Cache Middleware. NCache has implemented ASP.NET Core IDistributedCache interface that allows ASP.NET Core to seamlessly use NCache as Response Cache Middleware as well.

In addition to the above-mentioned code change, you need to have the following in your ASP.NET Core appsettings.json file.


  {
      "NCacheSettings": {
          "CacheName": "myPartitionReplicaCache",
          "EnableLogs": "True",
          "RequestTimeout": "90"
      }
  }

Benefits of NCache as Response Cache Middleware

If your ASP.NET Core application is high traffic and running in a load-balanced multi-server web farm, then you need to use a Distributed Cache as your Response Cache Middleware. And, NCache is the most powerful .NET Distributed Cache available.

It provides you the following benefits.

  1. 100% Native .NET / .NET Core Cache: NCache is the only truly native .NET Distributed Cache available in the market. All others are developed in C++ on Linux and later ported to Windows with limited compatibility to .NET. NCache fits into your .NET application stack and simplifies your cost of development and maintenance.
  2. Extremely Fast & Scalable: NCache is extremely fast for being an in-memory distributed cache. And, it also provides linear scalability due to which it never becomes a bottleneck for your ASP.NET Core application performance even under peak loads.
  3. High Availability: NCache provides a self-healing peer to peer clustering architecture that has no single point of failure. Additionally, NCache intelligently replicates ASP.NET Core Response Cache pages so there is no data loss in case a cache server goes down and at the same time minimum cost of replication.

What to Do Next?

Signup for monthly email newsletter to get latest updates.

Contact Us

PHONE

+1 (214) 764-6933 (US)

+44 20 7993 8327 (UK)

© Copyright Alachisoft 2002 - . All rights reserved.