RequestCachePolicy Class

Definition

定義使用 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
Inheritance
RequestCachePolicy
Derived

Examples

下列程式碼範例會建立 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;
}

Remarks

您可以使用 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.

Constructors

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.

Properties

Level

取得建構這個執行個體時所指定的 RequestCacheLevel 值。Gets the RequestCacheLevel value specified when this instance was constructed.

Methods

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

傳回這個執行個體的字串表示。Returns a string representation of this instance.

Applies to

See also