In this topic we would learn about
What is Response Caching
Pros of Response Caching
Constraints for Caching
On which request we can apply it
How to configure it inย .NET middleware
How can I cerify it and some real world examples as well
๐๐๐ฌ๐ข๐ ๐ฏ๐ข๐ฌ๐ข๐ญ ๐ญ๐จ ๐๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ ๐๐๐๐ก๐ข๐ง๐ ๐๐ง๐ ๐ข๐ญ๐ฌ ๐ข๐ฆ๐ฉ๐ฅ๐๐ฆ๐๐ง๐ญ๐๐ญ๐ข๐จ๐ง ๐ข๐งย .๐๐๐
Response caching is a technique for storing the responses of an API or web application in a cache so that they can be served faster to subsequent requests. The responses are stored in a cache with a key that uniquely identifies them, and the cache has a limited size and a policy for removing items when it becomes full.
๐๐๐ง๐๐๐ข๐ญ๐ฌ ๐จ๐ ๐๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ ๐๐๐๐ก๐ข๐ง๐ ?
1. Improved performance by reducing the load on the server.
2. Reduced server load, as it can serve the cached response instead of generating a new one.
3. Reduced bandwidth usages it reduces the amount of data that needs to be transferred between the server and the client.
4. Improved security as it can reduce the number of requests that reach the server, reducing the risk of certain types of attacks.
๐๐ง ๐ฐ๐ก๐ข๐๐ก ๐ซ๐๐ช๐ฎ๐๐ฌ๐ญ๐ฌ ๐ฐ๐ ๐๐๐ง ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ ๐๐๐๐ก๐ข๐ง๐
1. Get
2. Head
๐
๐๐ฐ ๐๐จ๐ง๐ฌ๐ญ๐ซ๐๐ข๐ง๐ญ๐ฌ ๐๐จ๐ซ ๐๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ ๐๐๐๐ก๐ข๐ง๐
1.The request must result in a server response with a 200 (OK) status code.
2.Response Caching Middleware must be placed before middleware that require caching. For more information, see ASP.NET Core Middleware.
3.The Authorization header must not be present.
4. Cache-Control header parameters must be valid, and the response must be marked public and not marked private.
5. The Content-Length header value (if set) must match the size of the response body.
๐๐จ๐ฆ๐ ๐ซ๐๐๐ฅ-๐ฐ๐จ๐ซ๐ฅ๐ ๐๐ฑ๐๐ฆ๐ฉ๐ฅ๐๐ฌ ๐จ๐ ๐๐๐ฌ๐ฉ๐จ๐ง๐ฌ๐ ๐๐๐๐ก๐ข๐ง๐
1. News website
2. E-commerce websites
In your application you can apply response caching to those requests whose response is changed after a time and you are sure about it.
๐๐จ๐ฐ ๐๐๐ง ๐ ๐ฏ๐๐ซ๐ข๐๐ฒ ๐ข๐ญ?
Create an application apply caching and then request it from Postman and set time to 60 minutes, you will notice that only first request will reach the controller, after that even if you try request will not reach controller.
If you like my work you can help me in growing through following ways
Clapย , Subscribe and Follow me.
You can Buy a Coffee for me.
#csharp #dotnet #dotnetcore #dotnet6 #responsecaching #caching