Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core WebAPI: Memory Caching vs Response Caching

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?

like image 399
AsValeO Avatar asked Jun 19 '18 09:06

AsValeO


People also ask

What are the different caching techniques available in .NET Core?

ASP.NET Core supports two types of caching out of the box: In-Memory Caching – This stores data on the application server memory. Distributed Caching – This stores data on an external service that multiple application servers can share.

What is response caching in .NET Core?

Response caching reduces the number of requests a client or proxy makes to a web server. Response caching also reduces the amount of work the web server performs to generate a response. Response caching is controlled by headers that specify how you want client, proxy, and middleware to cache responses.

What is Inmemory caching?

What is an In-Memory Cache? An in-memory cache is a data storage layer that sits between applications and databases to deliver responses with high speeds by storing data from earlier requests or copied directly from databases.


1 Answers

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). Responce Caching middleware adds required headers to the response.
  • In-memory caching helps you to store the data that changes infrequently and used during request processing. E.g. you support currency conversion for products price and use some third-party service to obtain conversion rate. If you know that service updates the rate once per day, you can store it in in-memory cache to speed up requests processing, since you don't need to call that service again for some time.
like image 58
Alex Riabov Avatar answered Sep 18 '22 11:09

Alex Riabov