HttpRequestCachePolicy 类

定义

为通过使用 HttpWebRequest 对象获取的资源定义应用程序的缓存要求。

public ref class HttpRequestCachePolicy : System::Net::Cache::RequestCachePolicy
public class HttpRequestCachePolicy : System.Net.Cache.RequestCachePolicy
type HttpRequestCachePolicy = class
    inherit RequestCachePolicy
Public Class HttpRequestCachePolicy
Inherits RequestCachePolicy
继承
HttpRequestCachePolicy

示例

下面的代码示例为应用程序域创建默认缓存策略,并将其重写为请求。

// The following method demonstrates overriding the
// caching policy for a request.
static WebResponse^ GetResponseNoCache( Uri^ uri )
{
   // Set a default policy level for the "http:" and "https" schemes.
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::Default );
   HttpWebRequest::DefaultCachePolicy = policy;

   // Create the request.
   WebRequest^ request = WebRequest::Create( uri );

   // Define a cache policy for this request only. 
   HttpRequestCachePolicy^ noCachePolicy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::NoCacheNoStore );
   request->CachePolicy = noCachePolicy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"IsFromCache? {0}", response->IsFromCache );
   
   return response;
}
// The following method demonstrates overriding the
// caching policy for a request.
public static WebResponse GetResponseNoCache(Uri uri)
{
    // Set a default policy level for the "http:" and "https" schemes.
    HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
    HttpWebRequest.DefaultCachePolicy = policy;
    // Create the request.
    WebRequest request = WebRequest.Create(uri);
    // Define a cache policy for this request only.
    HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
    request.CachePolicy = noCachePolicy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("IsFromCache? {0}", response.IsFromCache);
    return response;
}

注解

可以使用属性或应用程序或计算机配置文件为应用程序 DefaultCachePolicy 指定默认缓存策略。 有关详细信息,请参阅 <requestCaching> 元素(网络设置)

可以使用属性为单个请求 CachePolicy 指定缓存策略。

不支持 Web 服务的Caching。

构造函数

HttpRequestCachePolicy()

初始化 HttpRequestCachePolicy 类的新实例。

HttpRequestCachePolicy(DateTime)

使用指定的缓存同步日期初始化 HttpRequestCachePolicy 类的新实例。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan)

使用指定的生存期控件和时间值初始化 HttpRequestCachePolicy 类的新实例。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan)

使用指定的最大生存期、生存期控制值和时间值初始化 HttpRequestCachePolicy 类的新实例。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan, DateTime)

使用指定的最大生存期、生存期控制值、时间值和缓存同步日期初始化 HttpRequestCachePolicy 类的新实例。

HttpRequestCachePolicy(HttpRequestCacheLevel)

使用指定的缓存策略初始化 HttpRequestCachePolicy 类的新实例。

属性

CacheSyncDate

获取此实例的缓存同步日期。

Level

获取创建此实例时指定的 HttpRequestCacheLevel 值。

MaxAge

获取从缓存返回的资源所允许的最大生存期。

MaxStale

获取从缓存返回的资源所允许的最大过期值。

MinFresh

获取从缓存返回的资源所允许的最小新鲜值。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回此实例的字符串表示形式。

适用于

另请参阅