IIS has featured to set "Output Caching" on asp.net sites. I would like to know what is the benefit of this type of caching compared to caching done by our browser. I am wondering because if our browser has the power to cache content(such as js/css/image), why would .net implement feature such as output caching?
-
because a web request will have control headers. and output caching will inject things like "Cache-Control: private, max-age=31536000" – naveen Feb 22 '12 at 04:50
2 Answers
Imagine a page that takes a lot of server-side resources to create -- maybe database calls, heavy computation, etc.
If one user requests that page, and it gets cached by the browser, then the next time that user requests the same page, it will already be on their machine -- so it won't have to be generated by the server or transferred over the network again.
Next, imagine that a second user requests the same page. The fact that a copy of the page was cached by the first user's browser doesn't help. Without output caching, the server will need to perform those time-consuming operations all over again to generate the page.
If the page used output caching, then the results from the first time is was created would be stored in memory on the server, so the cached results could be sent in response to subsequent requests -- which saves time and server-side resources.

- 18,448
- 3
- 51
- 66
Think of it for multiple users, let´s say 100.
Without Output Caching IIS would have to process and generate the page for each user request so the page is processed 100 times.
With Output Caching IIS would have to process the page once (for the first user requesting it), then cache it and return the same version for the other 99 users.

- 116
- 3