ASP.NET Core WebAPI: Memory Caching vs Response Caching

2.9k Views Asked by At

ASP.NET Core provides both in-memory caching and response caching. Let's say that the app is ASP.NET Core WebAPI that brings data from SQL database to users with configured Responce Caching middleware. In what case is it useful to use a memory caching also?

1

There are 1 best solutions below

0
On BEST ANSWER

These caching strategies are supposed to play a quite different role:

  • Response caching is used to say clients that communicate with a server to cache the response on their side using specific headers (such as Cache-Control, Expires, etc). Response Caching middleware adds required headers to the response.
  • In-memory caching helps you to store the data that changes infrequently and is used during request processing. E.g. you support currency conversion for product prices and use some third-party service to obtain conversion rates. If you know that service updates the rate once per day, you can store it in an in-memory cache to speed up request processing, since you don't need to call that service again for some time.