ASP.NET Core response cache

By | 2019-06-25

ASP.NET Core comes with built-in support for response caching. Unlike cache-control header that tells client/proxies how long to cache data, the response cache will cache output of an action.

The advantage of caching is that you can decrease the amount of expensive operations on the server by caching the result.

Install

Use

The simplest form of this caching is to decorate an action with the ResponseCache attribute. Duration says how many seconds to cache the output.

Note that the output may vary depending on HTTP headers, query variables, or post data. If this is the case then you need to specify so. For example:

Response caching supports much more complex scenarios.

Leave a Reply

Your email address will not be published. Required fields are marked *