Edit

Share via


HttpCacheValidateHandler Delegate

Definition

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

C#
public delegate void HttpCacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus);

Parameters

context
HttpContext

The HttpContext object containing information about the current request.

data
Object

User-supplied data used to validate the cached item.

validationStatus
HttpValidationStatus

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

Examples

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

C#

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;
   }
   else 
   {
      status = HttpValidationStatus.Valid;
   }
}

Remarks

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)

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

Applies to

Product Versions
.NET Framework 1.1, 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

See also