RequestCachePolicy 类

定义

为通过使用 WebRequest 对象获取的资源定义应用程序的缓存要求。Defines an application's caching requirements for resources obtained by using WebRequest objects.

public ref class RequestCachePolicy
public class RequestCachePolicy
type RequestCachePolicy = class
Public Class RequestCachePolicy
继承
RequestCachePolicy
派生

示例

下面的代码示例创建一个策略,将 Level 设置为 CacheOnly,并使用它来设置 WebRequest的缓存策略。The following code example creates a policy with Level set to CacheOnly, and uses it to set the cache policy of a WebRequest.

static WebResponse^ GetResponseFromCache( Uri^ uri )
{
   RequestCachePolicy^ policy = gcnew RequestCachePolicy( RequestCacheLevel::CacheOnly );
   WebRequest^ request = WebRequest::Create( uri );
   request->CachePolicy = policy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"Policy level is {0}.", policy->Level );
   Console::WriteLine( L"Is the response from the cache? {0}", response->IsFromCache );
   return response;
}
public static WebResponse GetResponseFromCache(Uri uri)
{
     RequestCachePolicy policy = 
        new  RequestCachePolicy( RequestCacheLevel.CacheOnly);
    WebRequest request = WebRequest.Create(uri);
    request.CachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy level is {0}.", policy.Level.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);  
    return response;
    
} 

注解

可以通过使用 DefaultCachePolicy 属性或应用程序或计算机配置文件来指定应用程序的默认缓存策略。You can specify a default cache policy for your application by using the DefaultCachePolicy property or the application or machine configuration files. 有关详细信息,请参阅<requestCaching> 元素(网络设置)For more information, see <requestCaching> Element (Network Settings).

可以通过使用 CachePolicy 属性指定单个请求的缓存策略。You can specify the cache policy for an individual request by using the CachePolicy property.

不支持 Web 服务的缓存。Caching for Web services is not supported.

构造函数

RequestCachePolicy()

初始化 RequestCachePolicy 类的新实例。Initializes a new instance of the RequestCachePolicy class.

RequestCachePolicy(RequestCacheLevel)

初始化 RequestCachePolicy 类的新实例。Initializes a new instance of the RequestCachePolicy class. 使用指定的缓存策略。using the specified cache policy.

属性

Level

获取构造此实例时指定的 RequestCacheLevel 值。Gets the RequestCacheLevel value specified when this instance was constructed.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回此实例的字符串表示形式。Returns a string representation of this instance.

适用于

另请参阅