Share via


RequestCachePolicy Konstruktory

Definice

Inicializuje novou instanci RequestCachePolicy třídy.

Přetížení

RequestCachePolicy()

Inicializuje novou instanci RequestCachePolicy třídy.

RequestCachePolicy(RequestCacheLevel)

Inicializuje novou instanci RequestCachePolicy třídy. pomocí zadaných zásad mezipaměti.

RequestCachePolicy()

Zdroj:
RequestCachePolicy.cs
Zdroj:
RequestCachePolicy.cs
Zdroj:
RequestCachePolicy.cs

Inicializuje novou instanci RequestCachePolicy třídy.

public:
 RequestCachePolicy();
public RequestCachePolicy ();
Public Sub New ()

Příklady

Následující příklad ukazuje volání tohoto konstruktoru.

static WebResponse^ GetResponseUsingCacheDefault( Uri^ uri )
{
   // Set  the default cache policy level for the "http:" scheme.
   RequestCachePolicy^ policy = gcnew RequestCachePolicy;

   // Create the request.
   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 GetResponseUsingCacheDefault(Uri uri)
{
    // Set  the default cache policy level for the "http:" scheme.
    RequestCachePolicy policy = new RequestCachePolicy();
    // Create the request.
    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;
}

Poznámky

Tento konstruktor inicializuje Level vlastnost na Default.

Viz také

Platí pro

RequestCachePolicy(RequestCacheLevel)

Zdroj:
RequestCachePolicy.cs
Zdroj:
RequestCachePolicy.cs
Zdroj:
RequestCachePolicy.cs

Inicializuje novou instanci RequestCachePolicy třídy. pomocí zadaných zásad mezipaměti.

public:
 RequestCachePolicy(System::Net::Cache::RequestCacheLevel level);
public RequestCachePolicy (System.Net.Cache.RequestCacheLevel level);
new System.Net.Cache.RequestCachePolicy : System.Net.Cache.RequestCacheLevel -> System.Net.Cache.RequestCachePolicy
Public Sub New (level As RequestCacheLevel)

Parametry

level
RequestCacheLevel

A RequestCacheLevel , který určuje chování mezipaměti pro prostředky získané pomocí WebRequest objektů.

Výjimky

level není platná RequestCacheLevelhodnota .value.

Příklady

Následující příklad kódu vytvoří zásadu s Level nastavenou na CacheOnly. a použije ji k nastavení zásad mezipaměti objektu 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;
}

Poznámky

Tento konstruktor inicializuje Level vlastnost na level.

Hodnota RequestCacheLevel určuje, jestli je ukládání do mezipaměti povolené a kdy je možné mezipaměť použít. Další informace najdete v RequestCacheLevel dokumentaci.

Viz také

Platí pro