Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's different between "ResponseCache attribute" and "ResponseCache middleware" in asp.net core?

I know ResponseCache attribute can caching page in client side by http headers attribute cache-control.

And ResponseCache middleware, it caching page on server (same http headers as ResponseCache attribute).

I compare these, it seems no different, same features, same condition.

Server side caching is no different from ResponseCache attribute, they both don't let the request into controller action, or these have different request pipeline ?

So, What kind of scenarios would choose ResponseCache middleware/ ResponseCache attribute?

like image 471
Vic Avatar asked Oct 22 '25 20:10

Vic


1 Answers

From documentations and source code, we can find:

Response Caching Middleware

determines when responses are cacheable, stores responses, and serves responses from cache.

ResponseCache Attribute specifies the parameters necessary for setting appropriate headers in response caching.

It is used to configure and create (via IFilterFactory) a ResponseCacheFilter. The ResponseCacheFilter performs the work of updating the appropriate HTTP headers and features of the response. The filter:

  • Removes any existing headers for Vary, Cache-Control, and Pragma.

  • Writes out the appropriate headers based on the properties set in the ResponseCacheAttribute.

  • Updates the response caching HTTP feature if VaryByQueryKeys is set.

For more information, please check:

like image 142
Fei Han Avatar answered Oct 25 '25 21:10

Fei Han



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!