HttpRequestCachePolicy Classe

Definição

Define os requisitos de cache de um aplicativo para os recursos obtidos usando objetos HttpWebRequest.Defines an application's caching requirements for resources obtained by using HttpWebRequest objects.

public ref class HttpRequestCachePolicy : System::Net::Cache::RequestCachePolicy
public class HttpRequestCachePolicy : System.Net.Cache.RequestCachePolicy
type HttpRequestCachePolicy = class
    inherit RequestCachePolicy
Public Class HttpRequestCachePolicy
Inherits RequestCachePolicy
Herança
HttpRequestCachePolicy

Exemplos

O exemplo de código a seguir cria uma política de cache padrão para o domínio do aplicativo e a substitui por uma solicitação.The following code example creates a default cache policy for the application domain, and overrides it for a request.

// The following method demonstrates overriding the
// caching policy for a request.
static WebResponse^ GetResponseNoCache( Uri^ uri )
{
   // Set a default policy level for the "http:" and "https" schemes.
   HttpRequestCachePolicy^ policy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::Default );
   HttpWebRequest::DefaultCachePolicy = policy;

   // Create the request.
   WebRequest^ request = WebRequest::Create( uri );

   // Define a cache policy for this request only. 
   HttpRequestCachePolicy^ noCachePolicy = gcnew HttpRequestCachePolicy( HttpRequestCacheLevel::NoCacheNoStore );
   request->CachePolicy = noCachePolicy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"IsFromCache? {0}", response->IsFromCache );
   
   return response;
}
// The following method demonstrates overriding the
// caching policy for a request.
public static WebResponse GetResponseNoCache(Uri uri)
{
    // Set a default policy level for the "http:" and "https" schemes.
    HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
    HttpWebRequest.DefaultCachePolicy = policy;
    // Create the request.
    WebRequest request = WebRequest.Create(uri);
    // Define a cache policy for this request only.
    HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
    request.CachePolicy = noCachePolicy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("IsFromCache? {0}", response.IsFromCache);
    return response;
}

Comentários

Você pode especificar uma política de cache padrão para seu aplicativo usando a DefaultCachePolicy propriedade ou os arquivos de configuração do aplicativo ou da máquina.You can specify a default cache policy for your application by using the DefaultCachePolicy property or the application or machine configuration files. Para obter mais informações, consulte < > elemento requestCaching (configurações de rede).For more information, see <requestCaching> Element (Network Settings).

Você pode especificar a política de cache para uma solicitação individual usando a CachePolicy propriedade.You can specify the cache policy for an individual request by using the CachePolicy property.

Não há suporte para caching para serviços Web.Caching for Web services is not supported.

Construtores

HttpRequestCachePolicy()

Inicializa uma nova instância da classe HttpRequestCachePolicy.Initializes a new instance of the HttpRequestCachePolicy class.

HttpRequestCachePolicy(DateTime)

Inicializa uma nova instância da classe HttpRequestCachePolicy usando a data de sincronização de cache especificada.Initializes a new instance of the HttpRequestCachePolicy class using the specified cache synchronization date.

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan)

Inicializa uma nova instância da classe HttpRequestCachePolicy usando os valores temporais e de controle de idade especificados.Initializes a new instance of the HttpRequestCachePolicy class using the specified age control and time values.

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan)

Inicializa uma nova instância da classe HttpRequestCachePolicy usando o valor temporal, o valor de controle de idade e o valor de idade máxima especificados.Initializes a new instance of the HttpRequestCachePolicy class using the specified maximum age, age control value, and time value.

HttpRequestCachePolicy(HttpCacheAgeControl, TimeSpan, TimeSpan, DateTime)

Inicializa uma nova instância da classe HttpRequestCachePolicy usando o valor temporal, o valor de controle de idade, o valor de idade máxima e a data de sincronização de cache especificados.Initializes a new instance of the HttpRequestCachePolicy class using the specified maximum age, age control value, time value, and cache synchronization date.

HttpRequestCachePolicy(HttpRequestCacheLevel)

Inicializa uma nova instância da classe HttpRequestCachePolicy usando a política de cache especificada.Initializes a new instance of the HttpRequestCachePolicy class using the specified cache policy.

Propriedades

CacheSyncDate

Obtém a data de sincronização do cache para esta instância.Gets the cache synchronization date for this instance.

Level

Obtém o valor de HttpRequestCacheLevel especificado quando essa instância foi criada.Gets the HttpRequestCacheLevel value that was specified when this instance was created.

MaxAge

Obtém a idade máxima permitida para um recurso retornado do cache.Gets the maximum age permitted for a resource returned from the cache.

MaxStale

Obtém o valor de desatualização máxima permitido para um recurso retornado do cache.Gets the maximum staleness value that is permitted for a resource returned from the cache.

MinFresh

Obtém o valor de atualização mínima permitido para um recurso retornado do cache.Gets the minimum freshness that is permitted for a resource returned from the cache.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma representação de cadeia de caracteres dessa instância.Returns a string representation of this instance.

Aplica-se a