HttpCacheValidateHandler 委托

定义

表示一个方法,在从缓存提供某个缓存项之前将调用该方法来验证该项。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 * HttpValidationStatus -> unit
Public Delegate Sub HttpCacheValidateHandler(context As HttpContext, data As Object, ByRef validationStatus As HttpValidationStatus)

参数

context
HttpContext

包含有关当前请求的信息的 HttpContext 对象。The HttpContext object containing information about the current request.

data
Object

用于验证缓存项的用户提供的数据。User-supplied data used to validate the cached item.

validationStatus
HttpValidationStatus

一个 HttpValidationStatus 枚举值。An HttpValidationStatus enumeration value. 委托应设置该值来指示验证的结果。Your delegate should set this value to indicate the result of the validation.

继承
HttpCacheValidateHandler

示例

下面的代码示例演示如何向应用程序添加新的缓存验证委托。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;
   }
   else 
   {
      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
   Else
      status = HttpValidationStatus.Valid
   End If
End Sub
    

注解

如果缓存项在HttpCacheValidateHandler方法范围内无效,则从缓存中逐出该缓存项,并将该项的请求视为缓存未命中。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.

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅