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 the Cache-Control header

Add the Cache-Control header - ASP.NET Core Tutorial

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

Start my 1-month free trial

Add the Cache-Control header

- [Instructor] Before we dive in, I wanted to point out that I updated the exercise files with my solution to the challenge I posed at the end of the previous chapter. You can find the updated code in the Begin state of the exercise files for this video. If you've been following along throughout this course, you can copy those changes into your project. Or, it might be just easier to open the solution file in the exercise files folder and continue from there. Okay, let's add some caching to this API. ASP.NET Core uses the ResponseCache attribute to indicate that a particular response is cacheable. To demonstrate how this works, let's add caching to the InfoController. The data returned from this slash info route is as static resources and it's really not gonna change very often. Let's add ResponseCache and we'll say Duration equals, how about one day? We'll say 86400 seconds. Let's try out a request and see what's returned. I'll hit slash info. The response doesn't change, but we have…

Contents