什么是HttpCacheability.NoCache和Response.CacheControl = QUOT差异;无缓存"? [英] What is different between HttpCacheability.NoCache and Response.CacheControl = "no-cache"?

查看:230
本文介绍了什么是HttpCacheability.NoCache和Response.CacheControl = QUOT差异;无缓存"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是下面的两条线之间的有什么不同?

  Response.Cache.SetCacheability(HttpCacheability.NoCache);

  Response.CacheControl =无缓存;


解决方案

如果您通过阅读文件,一般有什么不同是不尽然。

但是,因为前者使用Cache对象( HttpCachePolicyBase 在Asp.Net 4或Asp.Net MVC)它提供了:

一)在响应对象的缓存策略的抽象,可以在测试场景非常有用

b)潜在适应未来发展,如果HTTP规范扩展因故意味着 NOCACHE 需要在响应多个头部,或其他微调的反应。

它还允许非缓存能力来根据客户端透明的能力进行调整的概念;这是在该HTTP确实演变的情况下重要 - 但也已在HTTP 1.0和1.1的客户端的情况下(1.0和1.1之间的差异是公概括在 HTTP 1.0 VS 1.1 )。

在第二行,你正在服用的责任是如何被应用的no-cache指令(使用有点神奇的字符串) - 理所当然的,它仍然是可测试的,但如果HTTP规范不会改变,那么你必须code自己周围。

最后,最好的设计使用 Response.Cache 对象比code直接头(它真正进入了自己的ETag的和若非修饰的-由于搬运,例如)。

what is the different between the two lines below? :

Response.Cache.SetCacheability(HttpCacheability.NoCache);

and

 Response.CacheControl = "no-cache";

解决方案

If you read through the documentation, generally, there isn't any difference at all.

However, since the former uses the Cache object (HttpCachePolicyBase in Asp.Net 4 or Asp.Net MVC) it provides:

a) An abstraction over the response object's caching policy that can be useful in testing scenarios

b) Potential future-proofing if the HTTP spec is extended for some reason to mean that NoCache needs more headers in the response, or other tweaks to the response.

It also allows the notion of 'non-cacheability' to be adapted according to the capabilities of the client transparently; which is important in the case that HTTP does evolve - but also already in the case of HTTP 1.0 and 1.1 clients (differences between 1.0 and 1.1 are well-summarised in HTTP 1.0 vs 1.1).

In the second line, you are taking responsibility for how the no-cache directive is applied (using a somewhat magic string) - granted, it's still testable, but if the HTTP spec does change then you have to code around it yourself.

Ultimately, it's better design to use the Response.Cache object than to code the headers directly (it really comes into its own for ETags and If-Not-Modified-Since handling, for example).

这篇关于什么是HttpCacheability.NoCache和Response.CacheControl = QUOT差异;无缓存"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆