输出缓存与浏览器缓存相比的优势
IIS 具有在 ASP.NET 站点上设置“输出缓存”的功能。我想知道这种类型的缓存与我们的浏览器进行的缓存相比有什么好处。 我想知道,如果我们的浏览器有能力缓存内容(例如js/css/image),为什么.net要实现输出缓存等功能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想象一个页面需要大量服务器端资源来创建——可能是数据库调用、繁重的计算等。
如果一个用户请求该页面,并且它被浏览器缓存,那么下次用户请求同一页面时,它已经在他们的机器上 - 因此不必由服务器生成或再次通过网络传输。
接下来,假设第二个用户请求同一页面。事实上,第一个用户的浏览器缓存了页面的副本,这一事实并没有帮助。如果没有输出缓存,服务器将需要重新执行这些耗时的操作来生成页面。
如果页面使用输出缓存,那么第一次创建的结果将存储在服务器的内存中,因此可以发送缓存的结果来响应后续请求,从而节省时间和服务器端资源。
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.
考虑多个用户,假设有 100 个用户。
如果没有输出缓存,IIS 将必须为每个用户请求处理并生成页面,因此页面会被处理 100 次。
使用输出缓存,IIS 必须处理页面一次(对于第一个请求它的用户),然后缓存它并为其他 99 个用户返回相同的版本。
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.