Caching Web Pages
In this lesson, we will learn how to control response caching.
We'll cover the following...
Responses returned by Web servers can be cached in various places during their path to their target client applications. They can be cached in various Internet intermediary nodes, and in the browser cache itself.
HTTP standard headers control the way a response must be cached and when it can be cached. ASP.NET Core supports Web response caching through the ResponseCacheAttribute
action filter that manipulates the HTTP headers that affect response caching. It also allows response caching on the Web server itself.
In the sections below, we will describe the HTTP caching headers, how to use the ResponseCacheAttribute
action filter, and how to cache responses on the server.
HTTP cache headers
The main HTTP header that affects response caching is Cache-Control
which can assume several commas separated values. The table below describes all allowed values:
Cache-Control value | Effect | Example |
---|---|---|
public | The response is not specific for a single user so, it can be stored in the browser and on all intermediary nodes. | public |
private | The response is specific for a single user so, it can be stored in the |