System.Web Namespace
Delegate method that is called when a cached item is validated. Cache items invalidated within the method are treated as cache misses.
[ VB ]
<Serializable>
public Delegate Sub HttpCacheValidateHandler ( _
ByVal context As HttpContext, _
ByVal data As Object, _
ByRef validationStatus As HttpValidationStatus _
)
[ C# ]
[ Serializable ]
public delegate void HttpCacheValidateHandler (
HttpContext context,
object data,
ref HttpValidationStatus validationStatus
);
[ C++ ]
[ Serializable ]
public __gc __delegate void HttpCacheValidateHandler (
HttpContext* context,
Object* data,
HttpValidationStatus* validationStatus
);
In [ JScript ], you can use the delegates in the .NET Framework, but you cannot define your own.
The declaration of your event handler must have the same parameters as the HttpCacheValidateHandler delegate declaration.
- context
- The HttpContext object containing information about the current request.
- data
- User-supplied data used to validate the cached item.
- validationStatus
- An HttpValidationStatus enumeration value. Your delegate should set this value to indicate the result of the validation.
If any handler invalidates the cached item, the item is evicted from the cache and the request is handled as a cache miss.
The following example adds a new cache validation delegate to an aplication.
[ VB ]
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
[ C# ]
private void Page_Load ( object src, 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;
}
}
HttpCachePolicy Class