简体   繁体   English

ASP.NET MVC中没有更改的智能缓存页面

[英]Smart Caching pages with no change in ASP.NET MVC

I am thinking about implementing caching mechanics for asp.net mvc pages that gives you the latest version of a web page, but if the page didn't changed since the last time it was cached, it will return the cached result. 我正在考虑为asp.net mvc页面实现缓存机制,从而为您提供最新版本的网页,但是如果该页面自上次缓存以来没有更改,它将返回缓存的结果。

By the way, I wonder what are the limits of OutputCacheAttribute caching - many Locations can be used - Client Side, Server Side, Down Streaming, Any (default) and more. 顺便说一下,我想知道OutputCacheAttribute缓存的限制是什么-可以使用许多位置-客户端,服务器端,下行流​​,任何(默认)等等。 I wonder which is the fastest option, because I don't know what is the client side limitations - if it can store all the cached data I think it will definitely be the best caching location. 我想知道哪个是最快的选择,因为我不知道客户端的限制是什么-如果它可以存储所有缓存的数据,我认为它肯定是最佳的缓存位置。 So what data can be stored in each location? 那么什么数据可以存储在每个位置?

A nice idea I came with is saving the last viewed page version of a certain address as hash inside a cookie, so when the user requests a page, I might give him the cached result if its hash didn't change. 我想到的一个好主意是将某个地址的上次查看页面版本保存为cookie中的哈希,因此,当用户请求页面时,如果哈希值没有变化,我可能会给他缓存的结果。 but If I calculate the current page hash, it might save traffic, but it still consume time for the server to process the request, so I still not sure what is the best way to implement it and how to yield the best results. 但是,如果我计算当前的页面哈希值,可能会节省流量,但仍然会浪费服务器处理请求的时间,因此我仍然不确定实现它的最佳方法是什么以及如何产生最佳结果。

Both insights and ideas for implementing this as sophisticate as possible would be awesome. 尽可能精巧地执行此操作的见解和想法都很棒。

Your idea sounds a lot like the http ETag header and 304 not modified response - http://en.wikipedia.org/wiki/HTTP_ETag#Typical_usage . 您的想法听起来很像http ETag标头和304未修改的响应-http: //en.wikipedia.org/wiki/HTTP_ETag#Typical_usage Basically you don't need the custom cookie as the protocol already supports this. 基本上,您不需要自定义Cookie,因为协议已支持此功能。

As for returning the cached version with little impact on the server, use a Output Cache attribute as you already mentioned. 至于返回对服务器影响很小的缓存版本,请使用您已经提到的Output Cache属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM