.NET API Reference

RequestCacheLevel Enum

Overview

The RequestCacheLevel enumeration specifies the caching behavior for a request made by the System.Net.WebRequest class and its derivatives.

Namespace: System.Net

Assembly: System.dll

Members

NameValueDescription
BypassCache0Never use the cache.
CacheOnly1Use only the cache; fail if the item is not cached.
CacheIfAvailable2Use the cache if the item exists, otherwise retrieve it from the network.
Revalidate3Validate the cached entry with the server before using it.
Default4Determine the caching behavior based on the request's URI scheme.
NoCacheNoStore5Do not cache and do not store the response locally.
Refresh6Retrieve a fresh copy from the server, updating the cache.
CacheOrNextRequest7Use the cached item if present; otherwise, store the next response in the cache.

Examples

Below is a simple console application that demonstrates how to set the RequestCacheLevel for a WebRequest object.

using System; using System.Net; class Program { static void Main() { var url = "https://example.com/api/data"; var request = WebRequest.Create(url); request.CachePolicy = new HttpRequestCachePolicy(RequestCacheLevel.CacheIfAvailable); using var response = request.GetResponse(); Console.WriteLine($"Response received from {(response.ResponseUri)}"); } }