RequestCachePolicy.Level 屬性

定義

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

public:
 property System::Net::Cache::RequestCacheLevel Level { System::Net::Cache::RequestCacheLevel get(); };
public System.Net.Cache.RequestCacheLevel Level { get; }
member this.Level : System.Net.Cache.RequestCacheLevel
Public ReadOnly Property Level As RequestCacheLevel

屬性值

RequestCacheLevel 值,指定使用 WebRequest 物件取得之資源的快取行為。A RequestCacheLevel value that specifies the cache behavior for resources obtained using WebRequest objects.

範例

下列程式碼範例會建立 CacheOnly 原則,並傳送要求。The following code example creates a CacheOnly policy and sends a request.

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;
} 

備註

應用程式通常會使用 Default 做為其快取原則層級。Applications typically use Default as their cache policy level. 使用 Default 層級時,有效的快取原則取決於目前的快取原則和快取中的內容存留期。Using the Default level, the effective cache policy is determined by the current cache policy and the age of the content in the cache. WebRequest.CachePolicy 屬性(如果不是 null)會決定對要求有效的快取原則。The WebRequest.CachePolicy property, if not null, determines the cache policy in effect for a request.

應用程式域的預設原則可以使用 DefaultCachePolicy 或應用程式或電腦設定檔來設定。The default policy for the application domain can be set using the DefaultCachePolicy or the application or machine configuration file. 如需詳細資訊,請參閱<requestcaching>> 元素(網路設定)For more information, see <requestCaching> Element (Network Settings).

適用於

另請參閱