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的原則, 並使用它來設定的快取原則WebRequestThe 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.

適用於

另請參閱