HttpRequestCachePolicy コンストラクター

定義

HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

オーバーロード

HttpRequestCachePolicy()

HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy(DateTime)

キャッシュ同期日時を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy(HttpRequestCacheLevel)

キャッシュ ポリシーを指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan)

保存期間の制御と日時の値を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan)

有効期限、保存期間の制御値、日時の値を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan, DateTime)

有効期限、保存期間の制御値、日時の値、キャッシュ同期日時を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

HttpRequestCachePolicy()

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

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

次のコード例では、このコンストラクターを使用してキャッシュ ポリシーを設定する方法を示します。

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

注釈

このコンストラクターは、Level プロパティを Default に初期化します。

適用対象

HttpRequestCachePolicy(DateTime)

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

キャッシュ同期日時を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

public:
 HttpRequestCachePolicy(DateTime cacheSyncDate);
public HttpRequestCachePolicy (DateTime cacheSyncDate);
new System.Net.Cache.HttpRequestCachePolicy : DateTime -> System.Net.Cache.HttpRequestCachePolicy
Public Sub New (cacheSyncDate As DateTime)

パラメーター

cacheSyncDate
DateTime

キャッシュされたリソースの再検証が必要となる日時を指定する DateTime オブジェクト。

次のコード例では、キャッシュ同期日に基づいてキャッシュ ポリシーを作成する方法を示します。

static HttpRequestCachePolicy^ CreateLastSyncPolicy( DateTime when )
{
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( when );
   Console::WriteLine( L"When: {0}", when );
   Console::WriteLine( policy->CacheSyncDate );
   return policy;
}
public static HttpRequestCachePolicy CreateLastSyncPolicy(DateTime when)
{
    HttpRequestCachePolicy policy =
       new HttpRequestCachePolicy(when);

    Console.WriteLine("When: {0}", when);
    Console.WriteLine(policy.CacheSyncDate.ToString());
    return policy;
}

注釈

キャッシュ同期日付を利用し、キャッシュ済みコンテンツを再検証する絶対的日付を指定できます。 キャッシュ同期日より前にキャッシュ エントリが最後に再検証された場合は、サーバーとの再検証が行われます。 キャッシュ同期日の後にキャッシュ エントリが再検証され、キャッシュされたエントリを無効にするサーバーの再検証要件がない場合は、キャッシュからのエントリが使用されます。 キャッシュ同期日付が未来の日付に設定されている場合、キャッシュ同期日付が過ぎるまで、要求のたびにエントリが再検証されます。

このコンストラクターは、Level プロパティを Default に初期化します。 CacheSyncDate プロパティは cacheSyncDate に初期化されます。

適用対象

HttpRequestCachePolicy(HttpRequestCacheLevel)

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

キャッシュ ポリシーを指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

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

パラメーター

次のコード例では、キャッシュ内のリソースをキャッシュから使用できるようにするキャッシュ ポリシーを作成する方法を示します。

static HttpRequestCachePolicy^ CreateCacheIfAvailablePolicy()
{
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::CacheIfAvailable );
   Console::WriteLine( policy );
   return policy;
}
public static HttpRequestCachePolicy CreateCacheIfAvailablePolicy()
{
    HttpRequestCachePolicy policy =
        new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);

    Console.WriteLine(policy.ToString());
    return policy;
}

注釈

このコンストラクターは、Level プロパティを level に初期化します。

値は HttpRequestCacheLevel 、キャッシュを有効にするかどうか、およびキャッシュを使用できるタイミングを制御します。 詳細については、ドキュメントを HttpRequestCacheLevel 参照してください。

適用対象

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan)

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

保存期間の制御と日時の値を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

public:
 HttpRequestCachePolicy(System::Net::Cache::HttpCacheAgeControl cacheAgeControl, TimeSpan ageOrFreshOrStale);
public HttpRequestCachePolicy (System.Net.Cache.HttpCacheAgeControl cacheAgeControl, TimeSpan ageOrFreshOrStale);
new System.Net.Cache.HttpRequestCachePolicy : System.Net.Cache.HttpCacheAgeControl * TimeSpan -> System.Net.Cache.HttpRequestCachePolicy
Public Sub New (cacheAgeControl As HttpCacheAgeControl, ageOrFreshOrStale As TimeSpan)

パラメーター

cacheAgeControl
HttpCacheAgeControl

HttpCacheAgeControl 列挙値、つまり MaxAgeMaxStale、または MinFresh の 1 つ。

ageOrFreshOrStale
TimeSpan

期間を指定する TimeSpan 値。

例外

cacheAgeControl パラメーターに指定した値が、このコントラクターでは使用できません。

次のコード例では、最小鮮度に基づいてキャッシュ ポリシーを作成する方法を示します。

static HttpRequestCachePolicy^ CreateMinFreshPolicy( TimeSpan span )
{
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpCacheAgeControl::MinFresh,span );
   Console::WriteLine( L"Minimum freshness {0}", policy->MinFresh );
   return policy;
}
public static HttpRequestCachePolicy CreateMinFreshPolicy(TimeSpan span)
{
    HttpRequestCachePolicy policy =
        new HttpRequestCachePolicy(HttpCacheAgeControl.MinFresh, span);
    Console.WriteLine("Minimum freshness {0}", policy.MinFresh.ToString());
    return policy;
}

注釈

値は cacheAgeControl パラメーター値の意味を ageOrFreshOrStale 定義し、関連付けられているプロパティを設定するために使用されます。 たとえば、 を指定 MaxStaleすると、 MaxStale プロパティは パラメーターの値に ageOrFreshOrStale 設定されます。

このコンストラクターは、Level プロパティを Default に初期化します。

適用対象

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan)

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

有効期限、保存期間の制御値、日時の値を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

public:
 HttpRequestCachePolicy(System::Net::Cache::HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale);
public HttpRequestCachePolicy (System.Net.Cache.HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale);
new System.Net.Cache.HttpRequestCachePolicy : System.Net.Cache.HttpCacheAgeControl * TimeSpan * TimeSpan -> System.Net.Cache.HttpRequestCachePolicy
Public Sub New (cacheAgeControl As HttpCacheAgeControl, maxAge As TimeSpan, freshOrStale As TimeSpan)

パラメーター

cacheAgeControl
HttpCacheAgeControl

HttpCacheAgeControl 値。

maxAge
TimeSpan

リソースの有効期限を指定する TimeSpan 値。

freshOrStale
TimeSpan

期間を指定する TimeSpan 値。

例外

cacheAgeControl パラメーターに指定された値は無効です。

次のコード例では、最小鮮度と最大有効期間に基づいてキャッシュ ポリシーを作成する方法を示します。

static HttpRequestCachePolicy^ CreateFreshAndAgePolicy( TimeSpan freshMinimum, TimeSpan ageMaximum )
{
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpCacheAgeControl::MaxAgeAndMinFresh,
       ageMaximum, freshMinimum );
   Console::WriteLine( policy );
   return policy;
}
public static HttpRequestCachePolicy CreateFreshAndAgePolicy(TimeSpan freshMinimum, TimeSpan ageMaximum)
{
    HttpRequestCachePolicy policy =
        new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMinFresh, ageMaximum, freshMinimum);
    Console.WriteLine(policy.ToString());
    return policy;
}

注釈

値は cacheAgeControl 、パラメーター値の freshOrStale 意味を解釈し、関連付けられたプロパティを設定するために使用されます。 たとえば、 を指定 MaxStaleすると、 MaxStale プロパティは パラメーターの値に freshOrStale 設定されます。 を指定 MaxAgeAndMaxStaleすると、 MaxAge プロパティは パラメーターの値を maxAge 使用して設定され、 MaxStale プロパティは パラメーターの freshOrStale 値を使用して設定されます。

または MaxAgeAndMinFreshを指定MaxAgeAndMaxStaleしない限り、 プロパティは設定されないことにMaxAge注意してください。

このコンストラクターは、Level プロパティを Default に初期化します。

適用対象

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan, DateTime)

ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs
ソース:
HttpRequestCachePolicy.cs

有効期限、保存期間の制御値、日時の値、キャッシュ同期日時を指定して、HttpRequestCachePolicy クラスの新しいインスタンスを初期化します。

public:
 HttpRequestCachePolicy(System::Net::Cache::HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale, DateTime cacheSyncDate);
public HttpRequestCachePolicy (System.Net.Cache.HttpCacheAgeControl cacheAgeControl, TimeSpan maxAge, TimeSpan freshOrStale, DateTime cacheSyncDate);
new System.Net.Cache.HttpRequestCachePolicy : System.Net.Cache.HttpCacheAgeControl * TimeSpan * TimeSpan * DateTime -> System.Net.Cache.HttpRequestCachePolicy
Public Sub New (cacheAgeControl As HttpCacheAgeControl, maxAge As TimeSpan, freshOrStale As TimeSpan, cacheSyncDate As DateTime)

パラメーター

cacheAgeControl
HttpCacheAgeControl

HttpCacheAgeControl 値。

maxAge
TimeSpan

リソースの有効期限を指定する TimeSpan 値。

freshOrStale
TimeSpan

期間を指定する TimeSpan 値。

cacheSyncDate
DateTime

キャッシュされたリソースの再検証が必要となる日時を指定する DateTime オブジェクト。

次のコード例では、最小鮮度、最大有効期間、キャッシュ同期日に基づいてキャッシュ ポリシーを作成する方法を示します。

static HttpRequestCachePolicy^ CreateFreshAndAgePolicy2( TimeSpan freshMinimum, TimeSpan ageMaximum, DateTime when )
{
   HttpRequestCachePolicy^ policy = 
       gcnew HttpRequestCachePolicy( HttpCacheAgeControl::MaxAgeAndMinFresh, 
       ageMaximum, freshMinimum, when );
   Console::WriteLine( policy );
   return policy;
   
   // For the following invocation: CreateFreshAndAgePolicy(new TimeSpan(5,0,0), new TimeSpan(10,0,0),         );
   // the output is:
   // Level:Automatic AgeControl:MinFreshAndMaxAge MinFresh:18000 MaxAge:36000
}
public static HttpRequestCachePolicy CreateFreshAndAgePolicy2(TimeSpan freshMinimum, TimeSpan ageMaximum, DateTime when)
{
    HttpRequestCachePolicy policy =
        new HttpRequestCachePolicy(HttpCacheAgeControl.MaxAgeAndMinFresh, ageMaximum, freshMinimum, when);
    Console.WriteLine(policy.ToString());
    return policy;
    // For the following invocation:
    // CreateFreshAndAgePolicy(new TimeSpan(5,0,0), new TimeSpan(10,0,0),);
    // the output is:
    // Level:Automatic
    // AgeControl:MinFreshAndMaxAge
    // MinFresh:18000
    // MaxAge:36000
}

注釈

値は cacheAgeControl 、パラメーター値の freshOrStale 意味を解釈し、関連付けられたプロパティを設定するために使用されます。 たとえば、 を指定 MaxStaleすると、 MaxStale プロパティは パラメーターの値に freshOrStale 設定されます。 を指定 MaxAgeAndMaxStaleすると、 MaxAge プロパティは パラメーターの値を maxAge 使用して設定され、 MaxStale プロパティは パラメーターの freshOrStale 値を使用して設定されます。

または MaxAgeAndMinFreshを指定MaxAgeAndMaxStaleしない限り、 プロパティは設定されないことにMaxAge注意してください。

このコンストラクターは、 プロパティを CacheSyncDatecacheSyncDate初期化し、 プロパティを LevelDefault初期化します。

適用対象