RequestCachePolicy.Level Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
A RequestCacheLevel value that specifies the cache behavior for resources obtained using WebRequest objects.
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;
}
Applications typically use Default as their cache policy level. Using the Default level, the effective cache policy is determined by the current cache policy and the age of the content in the cache. The WebRequest.CachePolicy property, if not null
, determines the cache policy in effect for a request.
The default policy for the application domain can be set using the DefaultCachePolicy or the application or machine configuration file. For more information, see <requestCaching> Element (Network Settings).
Proizvod | Verzije |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Povratne informacije o proizvodu .NET
.NET je projekt otvorenog koda. Odaberite vezu za slanje povratnih informacija: