The page will not be cached server-side unless you use the outputcache
feature. The code you listed is only caching client-side.

Signature
Ben Strackany
www.developmentnow.com
<a href="http://www.developmentnow.com">dn</a>
> I have ASP.NET pages that I want cached on BOTH the client and server
> sides. I am currently setting the cache policy through code rather
> than OutputCache directive:
>
> HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
> HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(10);
>
[quoted text clipped - 8 lines]
>
> Neal
Ben Strackany - 19 Nov 2004 23:22 GMT
My bad, I was reading it wrong. I should have said that your code is caching
client side & server side.
Response.Cache.SetExpires & Response.Cache.SetCacheability
are interchangeable with the @outputcache parameter
which AFAIK will invoke server-side & client-side caching per the location
parameter.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/c
pconOutputCache.asp

Signature
Ben Strackany
www.developmentnow.com
<a href="http://www.developmentnow.com">dn</a>
> The page will not be cached server-side unless you use the outputcache
> feature. The code you listed is only caching client-side.
[quoted text clipped - 4 lines]
> >
> > HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(10);
> > This seems to work fine as the pages are being cached on the client.
> > My question is does the page actually get cached on the client AND
[quoted text clipped - 6 lines]
> >
> > Neal
> I have ASP.NET pages that I want cached on BOTH the client and server
> sides. I am currently setting the cache policy through code rather
[quoted text clipped - 10 lines]
> returned? Or is the page re-executed on the server for every single
> client whose copy has expired?
In additon to Ben's reply, let me add you're confusing HTTP caching with
application server specific caching. Your code makes your content cacheable
on web clients and proxies, but has nothing to do with ASP.NET owns caching
facilities.
BTW, you should also call
TimeSpan ts = new TimeSpan(0, 10, 0);
HttpContext.Current.Response.Cache.SetMaxAge(ts);
for full HTTP 1.1 compliance.
Cheers,

Signature
Joerg Jooss
www.joergjooss.de
news@joergjooss.de
nkranes@gmail.com - 12 Nov 2004 22:28 GMT
So what you're saying is that to enable Client-side (HTTP) and Server
side (Application) caching I need to include the above code plus the
outputcache directive? According to the documentation, I thought
Response.Cache and the OutputCache were used interchangably?
>From help:
You can enable or disable page output caching for cache-capable devices
in the request stream either declaratively or programmatically as well.
In the @ OutputCache directive for a page you can use the Location
attribute to specify whether the page's output can be cached on proxy
servers, browser clients, the originating Web server, or all or none of
these. You can do the same programmatically using the
HttpCachePolicy.SetCacheability method to specify the appropriate
HttpCacheability enumeration value for your page.
Thoughts?
Joerg Jooss - 13 Nov 2004 11:09 GMT
> So what you're saying is that to enable Client-side (HTTP) and Server
> side (Application) caching I need to include the above code plus the
> outputcache directive?
No...
> According to the documentation, I thought
> Response.Cache and the OutputCache were used interchangably?
Yes, you can. Actually, I should have written "HttpCachePolicy mixes up HTTP
caching and application server specific caching".
There's no notion of caching content on the origin server in HTTP, thus
setting HTTP headers using @OutputCache or HttpCachePolicy only affects
downstream proxies or clients.
If you want to have your cake and eat it, use
<%@ OutputCache Duration="600" VaryByParam="None" Location="Any" %>
This will allow caching everywhere. Even if a client request gets back to
the origin ASP.NET server, it simply replies with the cached response but
counts down the "Cache-Control: max-age" header -- very nice!
Cheers,

Signature
Joerg Jooss
www.joergjooss.de
news@joergjooss.de
nkranes@gmail.com - 15 Nov 2004 20:24 GMT
I hate to say it but you are correct. The only way to cache on the
Server and Client seems to be using the OutputCache directive. I still
think the documentation for the caching API is a bit misleading in this
regard and that there should be a way to programmatically do this.
Thanks for your help!
Ben Strackany - 19 Nov 2004 23:56 GMT
The documentation seems to imply that they're interchangeable, but maybe
not.

Signature
Ben Strackany
www.developmentnow.com
<a href="http://www.developmentnow.com">dn</a>
> I hate to say it but you are correct. The only way to cache on the
> Server and Client seems to be using the OutputCache directive. I still
> think the documentation for the caching API is a bit misleading in this
> regard and that there should be a way to programmatically do this.
> Thanks for your help!
Joerg Jooss - 21 Nov 2004 08:22 GMT
> I hate to say it but you are correct. The only way to cache on the
> Server and Client seems to be using the OutputCache directive. I
> still think the documentation for the caching API is a bit misleading
> in this regard and that there should be a way to programmatically do
> this. Thanks for your help!
Actually, I didn't want to imply that the "Any" option is only available
through OutputCache directive. It was only your reply that made me check
again. And yes, there seems to be no direct equivalent of Location="Any"
when using the API, but I'm sure you can construct it using several
HttpCachePolicy calls.
Cheers,

Signature
Joerg Jooss
www.joergjooss.de
news@joergjooss.de