Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [398]

By Root 5682 0
an object of type HttpCacheVaryByParams, representing the list of parameters received by a GET or POST request that affects caching

When a cached page has several vary-by headers or parameters, a separate version of the page is available for each HTTP header type or parameter name.

Methods of the HttpCachePolicy Class


Table 18-11 shows the methods of the HttpCachePolicy class.

Table 18-11. HttpCachePolicy Class Methods

Method

Description

AddValidationCallback

Registers a callback function to be used to validate the page output in the server cache before returning it.

AppendCacheExtension

Appends the specified text to the Cache-Control HTTP header. The existing text is not overwritten.

SetAllowResponseInBrowserHistory

When this setting is true, the response is available in the browser’s History cache, regardless of the HttpCacheability option set on the server.

SetCacheability

Sets the Cache-Control HTTP header to any of the values taken from the HttpCacheability enumeration type.

SetETag

Sets the ETag header to the specified string. The ETag header is a unique identifier for a specific version of a document.

SetETagFromFileDependencies

Sets the ETag header to a string built by combining and then hashing the last modified date of all the files upon which the page is dependent.

SetExpires

Sets the Expires header to an absolute date and time.

SetLastModified

Sets the Last-Modified HTTP header to a particular date and time.

SetLastModifiedFromFileDependencies

Sets the Last-Modified HTTP header to the most recent timestamps of the files upon which the page is dependent.

SetMaxAge

Sets the max-age attribute on the Cache-Control header to the specified value. The sliding period cannot exceed one year.

SetNoServerCaching

Disables server output caching for the current response.

SetNoStore

Sets the Cache-Control: no-store directive.

SetNoTransforms

Sets the Cache-Control: no-transforms directive.

SetOmitVaryStar

If set to true, causes HttpCachePolicy to ignore the * value in VaryByHeaders.

SetProxyMaxAge

Sets the Cache-Control: s-maxage header.

SetRevalidation

Sets the Cache-Control header to either must-revalidate or proxy-revalidate.

SetSlidingExpiration

Sets cache expiration to sliding. When cache expiration is set to sliding, the Cache-Control header is renewed at each response.

SetValidUntilExpires

Specifies whether the ASP.NET cache should ignore HTTP Cache-Control headers sent by some browsers to evict a page from the cache. If this setting is true, the page stays in the cache until it expires.

SetVaryByCustom

Sets the Vary HTTP header to the specified text string.

Most methods of the HttpCachePolicy class let you control the values of some HTTP headers that relate to the browser cache. The AddValidationCallback method, on the other hand, provides a mechanism to programmatically check the validity of page output in the server cache before it is returned from the cache.

Server Cache-Validation Callback


Before the response is served from the ASP.NET cache, all registered handlers are given a chance to verify the validity of the cached page. If at least one handler marks the cached page as invalid, the entry is removed from the cache and the request is served as if it were never cached. The signature of the callback function looks like this:

public delegate void HttpCacheValidateHandler(

HttpContext context,

Object data,

ref HttpValidationStatus validationStatus

);

The first argument denotes the context of the current request, whereas the second argument is any user-defined data the application needs to pass to the handler. Finally, the third argument is a reference to a value from the HttpValidationStatus enumeration. The callback sets this value to indicate the result of the validation. Acceptable values are IgnoreThisRequest, Invalid, and Valid. In the case of IgnoreThisRequest, the cached resource is not invalidated but the request is served as if no response was ever cached. If the return value is Invalid, the cached

Return Main Page Previous Page Next Page

®Online Book Reader