网络应用程序的缓存管理Cache Management for Network Applications

本主题及其相关的副主题描述针对使用 WebClientWebRequestHttpWebRequestFtpWebRequest 类获取的资源的缓存。This topic and its related subtopics describe caching for resources obtained using the WebClient, WebRequest, HttpWebRequest, and FtpWebRequest classes.

缓存为已由应用程序请求的资源提供临时存储。A cache provides temporary storage of resources that have been requested by an application. 如果应用程序多次请求同一资源,则可以从此缓存中返回此资源,避免了重复向服务器发出请求的开销。If an application requests the same resource more than once, the resource can be returned from the cache, avoiding the overhead of re-requesting it from the server. 缓存可以通过减少获取请求的资源所需的时间,以提高应用程序性能。Caching can improve application performance by reducing the time required to get a requested resource. 缓存还可以通过减少对服务器的访问次数,以减少网络流量。Caching can also decrease network traffic by reducing the number of trips to the server. 虽然缓存提高了性能,但会增加返回到应用程序的资源已过时的风险,这意味着如果未使用缓存,返回到应用程序的资源则与由服务器发送的资源不同。While caching improves performance, it increases the risk that the resource returned to the application is stale, meaning that it is not identical to the resource that would have been sent by the server if caching were not in use.

缓存可以允许未经授权的用户或进程读取敏感数据。Caching may allow unauthorized users or processes to read sensitive data. 在无需进行额外授权的情况下,可以从缓存中检索缓存的已经过身份验证的响应。An authenticated response that is cached may be retrieved from the cache without an additional authorization. 如果已启用缓存,请将 CachePolicy 更改为 BypassCacheNoCacheNoStore 以针对此请求禁用缓存。If caching is enabled, change to CachePolicy to BypassCache or NoCacheNoStore to disable caching for this request.

出于安全考虑,不建议将缓存用于中间层方案 。Due to security concerns, caching is not recommended for middle tier scenarios.

本节内容In This Section

缓存策略Cache Policy
说明什么是缓存策略以及如何定义一个缓存策略。Explains what a cache policy is and how to define one.

基于位置的缓存策略Location-Based Cache Policies
定义基于位置的缓存策略的每个类型,此策略可用于超文本传输协议(http 和 https)资源。Defines each type of location-based cache policy available for Hypertext Transfer Protocol (http and https) resources.

基于时间的缓存策略Time-Based Cache Policies
描述可用于自定义基于时间的缓存策略的条件。Describes the criteria that can be used to customize a time-based cache policy.

在网络应用程序中配置缓存Configuring Caching in Network Applications
描述如何以编程方式创建缓存策略以及使用缓存的请求。Describes how to programmatically create cache policies and requests that use caching.

参考Reference

System.Net.Cache
定义类型和枚举,这些类型和枚举用于为使用 WebRequestHttpWebRequestFtpWebRequest 类获取的资源定义缓存策略。Defines the types and enumerations used to define cache policies for resources obtained using the WebRequest, HttpWebRequest, and FtpWebRequest classes.