473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to cache differrent versions of page and then call specific version from http request

I have a products catalogue that I'm putting online and there will be
between 20 to 50 different pages of products. Each page contains a datagrid
of products for a given category. However, the categories change from time
to time so the list of categories must be dynamic and database driven (as is
the menu used to select the category to load in the products page). The way
I see it there's 2 possible options. dynamically create each aspx page when
its not found in the system cache (for example if category 22 was selected
from the navigation menu then build a page called Cat_22.aspx, cache it and
then return it to the client), or build one page with one datagrid and cache
each different instance of it (one instance per category as they are
requested). If the 2nd option is the way to go, then I have 2 pointed
questions: 1) How do I cache different versions of this page and 2) How
do I call a specific version from the requesting browser?

Lastly, if it makes any difference, I'm using VS2003 and doing all of this
in a frameset where the nav menu is a web user control in the left-hand
frame called contents and the products are being displayed in the right hand
frame called main. So far I've been able to wire things up OK where the
menu can pass a category ID to a hidden control on the products page and
then call a button click event on the products page to do a postback and
return a datagrid with the products for that category. But in the future I
think this must be done differently since when a user selects a category
from the nav menu, an html page could be in the main frame such as the home
page or about us page. Therefore I would have to pass a url in the target
frame like:
Products.aspx?CategID=22 or something like that (although I've never used
this technique before).

Can someone please advise? Thanks.

--
mo*******@nospam.com
Nov 18 '05 #1
7 1490
I would do one page with the query string, as you mentioned
(Products.aspx?CategID=22 )
Then use output caching to have it cached on the server side (saves the time
to dynamically receate the page). The following caches for an hour (may be
an eternity) but every CategID gets its own version:

Put a line like this at the top of the aspx page:

<%@ OutputCache Duration="3600" VaryByParam="CategID" %>

Parsing the Query string is easy: (here in vb.net):

Dim CategID As String = Request.QueryString("CategID")

Hope that helps you get started...

--
Mike Mayer - Visual C# MVP
http://www.mag37.com/csharp/
mi**@mag37.com


"moondaddy" <mo*******@nospam.com> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
I have a products catalogue that I'm putting online and there will be
between 20 to 50 different pages of products. Each page contains a datagrid of products for a given category. However, the categories change from time to time so the list of categories must be dynamic and database driven (as is the menu used to select the category to load in the products page). The way I see it there's 2 possible options. dynamically create each aspx page when its not found in the system cache (for example if category 22 was selected
from the navigation menu then build a page called Cat_22.aspx, cache it and then return it to the client), or build one page with one datagrid and cache each different instance of it (one instance per category as they are
requested). If the 2nd option is the way to go, then I have 2 pointed
questions: 1) How do I cache different versions of this page and 2) How
do I call a specific version from the requesting browser?

Lastly, if it makes any difference, I'm using VS2003 and doing all of this
in a frameset where the nav menu is a web user control in the left-hand
frame called contents and the products are being displayed in the right hand frame called main. So far I've been able to wire things up OK where the
menu can pass a category ID to a hidden control on the products page and
then call a button click event on the products page to do a postback and
return a datagrid with the products for that category. But in the future I think this must be done differently since when a user selects a category
from the nav menu, an html page could be in the main frame such as the home page or about us page. Therefore I would have to pass a url in the target
frame like:
Products.aspx?CategID=22 or something like that (although I've never used
this technique before).

Can someone please advise? Thanks.

--
mo*******@nospam.com

Nov 18 '05 #2
Hi moondaddy,
Thanks for posting in the community!
From your description, you had a ASP.NET web page to retrieve certain
records from database via a certain key. And the key is passed by a
querystring in the url such as
"http://server/app/getdatapage.aspx?keystring= ....". For performance
issues, you'd like to cache the certain page's response via the keystring's
value so that when the certain page is requested via the same keystring, a
cached response will be output, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this question, I quite agree to Michael's suggestion that use the
Page's "OutputCache" attributes to specify caching a page's response output
stream. And the "VaryByParam" is used when specify the querystring param
depend on which the page will determine whether to generate a new version
or use the cached output response stream. For example:
<%@ OutputCache duration="60" varybyparam="CategID" %>
That instruct the page to determined whether to first retrieve page in
cache or generate new version according to the "CategID" param.

For more detailed info on using param caching for page's output, you may
view the following reference in MSDN:
#Caching Versions of a Page, Based on Parameters
http://msdn.microsoft.com/library/en...ingversionsofp
agebasedonparameters.asp?frame=true

Also, if you'd like more customized caching control, the ASP.NET also
provide custom output caching control via the
"VaryByCustom" attribute, and here is the tech reference on using this:

#Caching Versions of a Page, Based on Custom Strings
http://msdn.microsoft.com/library/en...ingversionsofp
agebasedoncustomstrings.asp?frame=true

Please check out the above items to see whether they're helpful. If you
need any further assistance, please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Thanks Steven & Mike! That works excellent. Now how about taking it one
step further and cache each version of the page on the client browser? Is
this possible and if so, how would I approach it?

--
mo*******@nospam.com
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:aY**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thanks for posting in the community!
From your description, you had a ASP.NET web page to retrieve certain
records from database via a certain key. And the key is passed by a
querystring in the url such as
"http://server/app/getdatapage.aspx?keystring= ....". For performance
issues, you'd like to cache the certain page's response via the keystring's value so that when the certain page is requested via the same keystring, a
cached response will be output, yes?
If there is anything I misunderstood, please feel free to let me know.

As for this question, I quite agree to Michael's suggestion that use the
Page's "OutputCache" attributes to specify caching a page's response output stream. And the "VaryByParam" is used when specify the querystring param
depend on which the page will determine whether to generate a new version
or use the cached output response stream. For example:
<%@ OutputCache duration="60" varybyparam="CategID" %>
That instruct the page to determined whether to first retrieve page in
cache or generate new version according to the "CategID" param.

For more detailed info on using param caching for page's output, you may
view the following reference in MSDN:
#Caching Versions of a Page, Based on Parameters
http://msdn.microsoft.com/library/en...ingversionsofp agebasedonparameters.asp?frame=true

Also, if you'd like more customized caching control, the ASP.NET also
provide custom output caching control via the
"VaryByCustom" attribute, and here is the tech reference on using this:

#Caching Versions of a Page, Based on Custom Strings
http://msdn.microsoft.com/library/en...ingversionsofp agebasedoncustomstrings.asp?frame=true

Please check out the above items to see whether they're helpful. If you
need any further assistance, please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Hi moondaddy,
Thanks for your response. I'm glad the preceding suggestions have worked
for you. As for the new question on "caching the multi-version of pages on
client side" you mentioned in the reply, I think the ASP.NET's page cache
mechanism doesn't provide such functions. The ASP.NET page's output caches
are all stored on the serverside's caching memory. As for the page's cache
on client side's browser, this is the default behavior, every response to
client brower will has a cache at the client unless you manually disabled
it, that's why if you view a page and then navigator to another page and
use the "back" button on the browser to turn back to the former page, we
can still see the former version of the former one, yes? However, if we
request the page again(use the "refresh" button), the browser will request
a new version of the certain page rather than use the client side's cache.
So I'm afraid the multi-verion output cache is limited to the serverside ,
do you think so?
If you have any questions, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
You can flag a response to be stored on the client by using the Expires and
Cache-Control headers.

Response.Cache.SetExpires(dtExpires);
Response.Cache.SetMaxAge(dtExpires - dtNow);

Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:no**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thanks for your response. I'm glad the preceding suggestions have worked
for you. As for the new question on "caching the multi-version of pages on client side" you mentioned in the reply, I think the ASP.NET's page cache
mechanism doesn't provide such functions. The ASP.NET page's output caches
are all stored on the serverside's caching memory. As for the page's cache
on client side's browser, this is the default behavior, every response to
client brower will has a cache at the client unless you manually disabled
it, that's why if you view a page and then navigator to another page and
use the "back" button on the browser to turn back to the former page, we
can still see the former version of the former one, yes? However, if we
request the page again(use the "refresh" button), the browser will request
a new version of the certain page rather than use the client side's cache.
So I'm afraid the multi-verion output cache is limited to the serverside ,
do you think so?
If you have any questions, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
This sounds interesting but I don't fully understand (still green at web
dev.). Can you please elaborate a bit by telling me how/where to use this
line of code? Thanks in advance!

--
mo*******@nospam.com
"Eric Lawrence [MSFT]" <e_********@hotmail.com> wrote in message
news:OQ*************@TK2MSFTNGP12.phx.gbl...
You can flag a response to be stored on the client by using the Expires and Cache-Control headers.

Response.Cache.SetExpires(dtExpires);
Response.Cache.SetMaxAge(dtExpires - dtNow);

Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:no**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thanks for your response. I'm glad the preceding suggestions have worked for you. As for the new question on "caching the multi-version of pages

on
client side" you mentioned in the reply, I think the ASP.NET's page cache mechanism doesn't provide such functions. The ASP.NET page's output caches are all stored on the serverside's caching memory. As for the page's cache on client side's browser, this is the default behavior, every response to client brower will has a cache at the client unless you manually disabled it, that's why if you view a page and then navigator to another page and
use the "back" button on the browser to turn back to the former page, we
can still see the former version of the former one, yes? However, if we
request the page again(use the "refresh" button), the browser will request a new version of the certain page rather than use the client side's cache. So I'm afraid the multi-verion output cache is limited to the serverside , do you think so?
If you have any questions, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #7
"moondaddy" <mo*******@nospam.com> wrote in message news:<uS**************@TK2MSFTNGP09.phx.gbl>...
This sounds interesting but I don't fully understand (still green at web
dev.). Can you please elaborate a bit by telling me how/where to use this
line of code? Thanks in advance!

--
mo*******@nospam.com
"Eric Lawrence [MSFT]" <e_********@hotmail.com> wrote in message
news:OQ*************@TK2MSFTNGP12.phx.gbl...
You can flag a response to be stored on the client by using the Expires

and
Cache-Control headers.

Response.Cache.SetExpires(dtExpires);
Response.Cache.SetMaxAge(dtExpires - dtNow);

Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no

rights.


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:no**************@cpmsftngxa07.phx.gbl...
Hi moondaddy,
Thanks for your response. I'm glad the preceding suggestions have worked for you. As for the new question on "caching the multi-version of pages on client side" you mentioned in the reply, I think the ASP.NET's page cache mechanism doesn't provide such functions. The ASP.NET page's output caches are all stored on the serverside's caching memory. As for the page's cache on client side's browser, this is the default behavior, every response to client brower will has a cache at the client unless you manually disabled it, that's why if you view a page and then navigator to another page and
use the "back" button on the browser to turn back to the former page, we
can still see the former version of the former one, yes? However, if we
request the page again(use the "refresh" button), the browser will request a new version of the certain page rather than use the client side's cache. So I'm afraid the multi-verion output cache is limited to the serverside , do you think so?
If you have any questions, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


put in the page load event and make sure that the page not postback i.e
void Page_Load()
{
if (!this.isPostBack)
{
// cache...
}
}
Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Just D. | last post by:
All, Did anybody see this strange effect? The web application is written in C#, ASP.NET, SQL, T-SQL, etc. A pretty usual stuff, complicated enough, but works fine until... Here is a question....
7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
4
by: sviau | last post by:
should cache-control be set to public or private on dynamic site. our content doesnt change for 24hrs, but because results from search pages vary so much, we cant cache the pages themselves. ...
4
by: Erick | last post by:
i have an asp.net application and I want to save the results of an sql query in cache. Because the queries take 28 seconds to run (there are twelve similar queries) I want to run it all at 4am, ...
2
by: Kikoz | last post by:
Hi all. I keep my ViewState in server's cache. Works fine except when user leaves the page opened for a long time (2 hours or so). Then if he/she tries to post it back the server throws an...
14
by: Tom.PesterDELETETHISSS | last post by:
Hi, I think this question requires an in depth understanding of how a browser cache works. I hope I can reach an expert here. I may have found a quirk in the asp.net documentation or I don't...
3
by: wardemon | last post by:
Hi All, I have a aspx page named: ImageProcess.aspx that creates a thumbnail version of an image by passing the ImagePath, width, and height. The ImagePath is taken from a table from a database,...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
8
by: Rory Becker | last post by:
Hi All I have a need for an asp.net page to make a call to a server which it did not originate from when a button is clicked. A simple call to pass 2-3 params and return a result. I am happy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.