From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add server-side caching

Add server-side caching - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Add server-side caching

- [Instructor] There's one other type of caching that ASP.NET Core supports, and that's server side caching. Server side caching means that your server can cache responses that are expensive to generate but don't change very often. This can be one more useful way to reduce load on your server and improve response time. To enable server side caching, you'll need to add a middleware component to your application pipeline. Over in Startup.cs, first in the configure services method, we need to add services.AddReponseCaching. And then down at the bottom in the configure method, above UseMvc, we'll do app.UseResponseCaching. The order here is important. UseResponseCaching needs to be above UseMvc or any other middleware that produces a response. The response caching middleware uses the same response cache attribute we used before to add the cache control headers for client side caching. Let's try putting the response cache attribute on a big collection response that takes some time to…

Contents