HighTechTalks DotNet Forums  

Output Caching on the Server AND Client

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss Output Caching on the Server AND Client in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
nkranes (AT) gmail (DOT) com
 
Posts: n/a

Default Output Caching on the Server AND Client - 11-12-2004 , 12:09 PM






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.SetValidUntilEx pires(true);
HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(Date Time.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
server side. I.e. After a page is expired on the client and a request
is made to the server, is a server-side cached version of the page
returned? Or is the page re-executed on the server for every single
client whose copy has expired?

Thanks in advance!

Neal


Reply With Quote
  #2  
Old   
Ben Strackany
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-12-2004 , 04:39 PM






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

--
Ben Strackany
www.developmentnow.com

<a href="http://www.developmentnow.com">dn</a>


<nkranes (AT) gmail (DOT) com> wrote

Quote:
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.SetValidUntilEx pires(true);

HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(Date Time.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
server side. I.e. After a page is expired on the client and a request
is made to the server, is a server-side cached version of the page
returned? Or is the page re-executed on the server for every single
client whose copy has expired?

Thanks in advance!

Neal




Reply With Quote
  #3  
Old   
Joerg Jooss
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-12-2004 , 04:58 PM



nkranes (AT) gmail (DOT) com wrote:
Quote:
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.SetValidUntilEx pires(true);
HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(Date Time.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
server side. I.e. After a page is expired on the client and a request
is made to the server, is a server-side cached version of the page
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,

--
Joerg Jooss
www.joergjooss.de
news (AT) joergjooss (DOT) de





Reply With Quote
  #4  
Old   
nkranes (AT) gmail (DOT) com
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-12-2004 , 05:28 PM



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?

Quote:
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?



Reply With Quote
  #5  
Old   
Joerg Jooss
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-13-2004 , 06:09 AM



nkranes (AT) gmail (DOT) com wrote:
Quote:
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...

Quote:
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,

--
Joerg Jooss
www.joergjooss.de
news (AT) joergjooss (DOT) de




Reply With Quote
  #6  
Old   
nkranes (AT) gmail (DOT) com
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-15-2004 , 03:24 PM



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!


Reply With Quote
  #7  
Old   
Ben Strackany
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-19-2004 , 06:22 PM



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/de...utputCache.asp

--
Ben Strackany
www.developmentnow.com

<a href="http://www.developmentnow.com">dn</a>


"Ben Strackany" <infoNOSPAM (AT) developmentnow (DOT) nospam.com> wrote

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

--
Ben Strackany
www.developmentnow.com

a href="http://www.developmentnow.com">dn</a


nkranes (AT) gmail (DOT) com> wrote in message
news:1100279380.242934.198830 (AT) c13g2000cwb (DOT) googlegroups.com...
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.SetValidUntilEx pires(true);


HttpContext.Current.Response.Cache.SetCacheability (HttpCacheability.Public);

HttpContext.Current.Response.Cache.SetExpires(Date Time.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
server side. I.e. After a page is expired on the client and a request
is made to the server, is a server-side cached version of the page
returned? Or is the page re-executed on the server for every single
client whose copy has expired?

Thanks in advance!

Neal






Reply With Quote
  #8  
Old   
Ben Strackany
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-19-2004 , 06:56 PM



The documentation seems to imply that they're interchangeable, but maybe
not.

--
Ben Strackany
www.developmentnow.com

<a href="http://www.developmentnow.com">dn</a>


<nkranes (AT) gmail (DOT) com> wrote

Quote:
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!




Reply With Quote
  #9  
Old   
Joerg Jooss
 
Posts: n/a

Default Re: Output Caching on the Server AND Client - 11-21-2004 , 03:24 AM



nkranes (AT) gmail (DOT) com wrote:
Quote:
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,

--
Joerg Jooss
www.joergjooss.de
news (AT) joergjooss (DOT) de




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.