HttpCacheValidateHandler HttpCacheValidateHandler HttpCacheValidateHandler HttpCacheValidateHandler Delegate


Represents a method that is called to validate a cached item before the item is served from the cache.

public delegate void HttpCacheValidateHandler(HttpContext ^ context, System::Object ^ data, HttpValidationStatus % validationStatus);
public delegate void HttpCacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus);
type HttpCacheValidateHandler = delegate of HttpContext * obj *  -> unit
Public Delegate Sub HttpCacheValidateHandler(context As HttpContext, data As Object, ByRef validationStatus As HttpValidationStatus)


HttpContext HttpContext HttpContext HttpContext

The HttpContext object containing information about the current request.

Object Object Object Object

User-supplied data used to validate the cached item.

HttpValidationStatus HttpValidationStatus HttpValidationStatus HttpValidationStatus

An HttpValidationStatus enumeration value. Your delegate should set this value to indicate the result of the validation.



The following code example demonstrates how to add a new cache validation delegate to an application.

private void Page_Load(Object sender, EventArgs e)
   Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(CacheValidate1), null);

public void CacheValidate1(HttpContext context, Object data, ref HttpValidationStatus status) 
   if (context.Request.QueryString["Valid"] == "false") 
      status = HttpValidationStatus.Invalid;
      status = HttpValidationStatus.Valid;

Private Sub Page_Load(sender As Object, e As EventArgs)
   Response.Cache.AddValidationCallback(New HttpCacheValidateHandler(AddressOf CacheValidate1), Nothing)
End Sub
Public Sub CacheValidate1(context As HttpContext, data As Object, ByRef status As HttpValidationStatus)
   If context.Request.QueryString("Valid") = "false" Then
      status = HttpValidationStatus.Invalid
      status = HttpValidationStatus.Valid
   End If
End Sub


If a cached item is invalidated within the scope of the HttpCacheValidateHandler method, it is evicted from the cache and the request for the item is treated as a cache miss.

Extension Methods

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Gets an object that represents the method represented by the specified delegate.

Applies to

See also