Another important function of Response object is the output of HTTP headers to
the client. As part of the HTTP header, these types of response objects should
be sent before sending any body content to the client.
Response.CacheControl Property
Response.CacheControl property set the value of
the HTTP/1.1 Cache-Control header in the Response.Syntax to indicate whether the
proxy servers or other cache mechanism can cache the HTML output.
Syntax:
Response.CacheControl [=Cache Control Header]
Or in an ASP file. Imply
<% Response.CacheControl = Cache Control Header %>
Parameters:
Cache Control Header
The parameter "Cache
Control Header" is the value of the HTTP/1.1 Cache-Control header to output in
the HTTP header. The data type of
"Cache Control Header" is strings and the value must be enclosed in quotation marks (" "). The
possible values of Cache Control Header are
Value
Description
public
To specify the response can be cached by a shared caches and
to indicate that the responses can be sent to any client
private
Default value; To specify the response can be cached by a
private or non-shared cache and to indicate that the response is only intended
for the specified client. The term "private" only specify the type of cached
used not the privacy of the response.
no-cache
To specify the response cannot be reused for the subsequent
request and to indicate that the cached responses cannot be reused again even
the response for the same client
no-store
To specify no part of the response can be stored in any type of non-volatile storage
for both the shared and the private caches. Th
max-age = delta-seconds
To specify the maximum amount of time before the cached response in a cache
be considered as expired. The "max-age" directive also overrides the Expires
Header. In general, the response is cacheable unless other restrictive cache
directive is also present.
s-maxage = delta-seconds
To specify the maximum amount of time before the cached response in a
public or shared cache be considered as expired. The "s-maxage" directive also
overrides both the Expires Header and the "max-age" directive.
must-revalidate
To specify the cached response should follow the
cache control directive for supporting a reliable operation or transaction and
to inform the cache that the cached response should be revalidated with the
original server after the cached response is stale.
proxy-revalidate
To specify the cached response in a public or
shared cache should follow the cache control directive for supporting a reliable
operation or transaction and to inform the public or shared cache that the
cached response should be revalidated with the original server after the cached
response is stale.
no-transform
To specify both the non-modifiable headers and any
aspect of the entity-body specified by the non-modifiable headers of the cached response
in a cache should not be transform
cache-extension
To extend
the Cache-Control header field through the adding of additional informational
extensions and behavioral modifier extensions. The new cache extension, if
understanded by the application will be recognized as the additional modifier
that associated with the standard cache control directive. Or the new cache
extension will be ignored and the application will default to the standard cache
control directive
Remarks:
The Cache-Control response header was added to HTTP 1.1 for defining how the
pages should be handled by caches.
If there is no cache mechanism between the web server and the client, or the
proxy server is running HTTP/1.0, the Cache-Control response header will be
ignored
If the response buffering is not enbled, the CacheControl header setting must be
set before any response is sent to the client.
The default value of Cache-Control response header of the IIS web server is
"Private" which tells cache not to cache pages. Setting the value of
Cache-Control response header to "Public" which tells cache to cache page for
faster response times. But dynamic pages generated by the response of ASP file
may also be interfered by the cache which might delay the response.
Examples:
Default value with No Response.CacheControl
ASP script command:
<% %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: private
Response.CacheControl
with value "public"
ASP script command:
<% Response.CacheControl = "public" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: public
Response.CacheControl with value "no-cache"
ASP script command:
<% Response.CacheControl = "no-cache" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: no-cache
Response.CacheControl with value "no-store"
ASP script command:
<% Response.CacheControl = "no-store" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: no-store
Response.CacheControl with value "max-age=86400"
ASP script command:
<% Response.CacheControl = "max-age=86400" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: max-age=86400
Response.CacheControl with value "s-maxage=86400"
ASP script command:
<% Response.CacheControl = "s-maxage=86400" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: s-maxage=86400
Response.CacheControl with value "must-revalidate"
ASP script command:
<% Response.CacheControl = "must-revalidate" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: must-revalidate
Response.CacheControl with value "proxy-revalidate"
ASP script command:
<% Response.CacheControl = "proxy-revalidate" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: proxy-revalidate
Response.CacheControl with value "no-transform"
ASP script command:
<% Response.CacheControl = "no-transform" %>
HTTP header response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: no-transform
Response.CacheControl with cache-extension
Example from rfc2616, a cache-extension of new "community"
value is added as
the modifier directive to the "private" value.
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: max-age=86400,
must-revalidate
Response.CacheControl with multiple
values
Example:
public value plus no-cache value to specify that the response can be cached in a
public cache but the response cannot be reused for the subsequent
request again even
for the same client.
ASP script command:t command:
<% Response.CacheControl = "public,
no-cache" %>
HTTP header response: response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Tue, 31 Jan 2012 15:19:08 GMT
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html Set-Cookie: ASPSESSIONIDPPPP=PPPPPPPP; path=/
Cache-control: public, no-cache