HighTechTalks DotNet Forums  

Caching Advice Required

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


Discuss Caching Advice Required in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
greg
 
Posts: n/a

Default Caching Advice Required - 11-30-2004 , 06:47 PM






I have an ASP app that i'm porting over ASP.Net

In an asp page i have many server.execute statements.

So in the asp page code i have something like this

<%
session("objectid") = 1001778
server.execute("multimedia.aspx")

session("objectid") = 1001779
server.execute("multimedia.aspx")

session("objectid") = 1001899
server.execute("listrecords.aspx")

session("objectid") = 1001778
server.execute("multimedia.aspx")



%>

Now i want only some code on the multimedia.aspx page to be cached as some
of the queries on the page are dynamic.
However i also want the page caching to vary based upon the objectid number
in the session variable. (BTW i am using a method that allows ASP sessions
to be shared with ASP.net sessions).

what i don't quite understand is that if i set the OUTPUTCACHE at the top of
page (in the .aspx file) to be cached and i use user controls in the ASPX
page for the dynamic queries is it possible to set the user controls so they
are not cached or ....
can you only do it the other way round and have the cached portion in user
controls.

An example of the multimedia.aspx file logic may read something like this:

run query to get parameters for this multimedia object using the session
objectid variable as a parameter
output html (ie table with colours) based upon this query (this is what i
want to cache)

then run query to get a list of .gifs from the database (they can change
regularly so i want this dynamic)
output html (not cached)

--------------------------------------------------------------------------------
The same multimedia.aspx can appear twice (with the same session objectid as
a parameter) on the same ASP page. In each multimedia.aspx page that gets
passed a different session objectid the html output varys slightly (ie table
colours etc.)


Thanks.











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

Default Re: Caching Advice Required - 11-30-2004 , 07:32 PM






One easy way to handle all that would be to use data caching. Create a
"multimedia" user control that has an ObjectID property. The user control's
code takes that objectid, calls the database, gets a dataset back, builds
some HTML, & returns it. Your user control could cache the dataset e.g.

Cache.Insert("dataset"+this.ObjectID,dsTheResults)

Or it could build the HTML from the dataset & just cache the resulting HTML

Cache.Insert("html"+this.ObjectID,strSomeHTML)

The code would do the normal stuff of checking the cache for null,
repopulating it as needed (maybe with delgates), etc.

If you were set on using outputcaching you'd put the outputcache into the
multimedia control, not the ASPX, & use one of the varyby* attributes. But I
think that'll prove more trouble than it's worth in this situation.

--
Ben Strackany
www.developmentnow.com

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


"greg" <greg_platt (AT) hotmail (DOT) com> wrote

Quote:
I have an ASP app that i'm porting over ASP.Net

In an asp page i have many server.execute statements.

So in the asp page code i have something like this

%
session("objectid") = 1001778
server.execute("multimedia.aspx")

session("objectid") = 1001779
server.execute("multimedia.aspx")

session("objectid") = 1001899
server.execute("listrecords.aspx")

session("objectid") = 1001778
server.execute("multimedia.aspx")



%

Now i want only some code on the multimedia.aspx page to be cached as some
of the queries on the page are dynamic.
However i also want the page caching to vary based upon the objectid
number
in the session variable. (BTW i am using a method that allows ASP sessions
to be shared with ASP.net sessions).

what i don't quite understand is that if i set the OUTPUTCACHE at the top
of
page (in the .aspx file) to be cached and i use user controls in the ASPX
page for the dynamic queries is it possible to set the user controls so
they
are not cached or ....
can you only do it the other way round and have the cached portion in user
controls.

An example of the multimedia.aspx file logic may read something like this:

run query to get parameters for this multimedia object using the session
objectid variable as a parameter
output html (ie table with colours) based upon this query (this is what i
want to cache)

then run query to get a list of .gifs from the database (they can change
regularly so i want this dynamic)
output html (not cached)

--------------------------------------------------------------------------
------
The same multimedia.aspx can appear twice (with the same session objectid
as
a parameter) on the same ASP page. In each multimedia.aspx page that gets
passed a different session objectid the html output varys slightly (ie
table
colours etc.)


Thanks.













Reply With Quote
  #3  
Old   
greg
 
Posts: n/a

Default Re: Caching Advice Required - 11-30-2004 , 11:27 PM



Thanks,
That sounds good but what i don't quite understand is how i cache around the
dynamic stuff.
For example in the multimedia.aspx

I run a query based upon parameter (session variable) then i output html
which you say i can cache.
Problem is that the dynamic queries appear in the page logic inbetween the
html i want to cache.

So i run the first query
then i might say something like this.
<%
if object.recordcount=1 then
%><%=html%><%
// run dynamic query and output some dynamic html
%><%=morehtml%><%

else

%><%=html%><%
// run dynamic query here and output some dynamic html
%><%=morehtml%><%

end if
%>

how do i easily cache the html around the dynamic queries?
With your method wouldn't i require lots of cache inserts for each block of
html?

So ideally i would like to cache the aspx page but run some usercontrols
(with no caching) to output the dynamic stuff
I'm not sure if this is possible however.


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

Quote:
One easy way to handle all that would be to use data caching. Create a
"multimedia" user control that has an ObjectID property. The user
control's
code takes that objectid, calls the database, gets a dataset back, builds
some HTML, & returns it. Your user control could cache the dataset e.g.

Cache.Insert("dataset"+this.ObjectID,dsTheResults)

Or it could build the HTML from the dataset & just cache the resulting
HTML

Cache.Insert("html"+this.ObjectID,strSomeHTML)

The code would do the normal stuff of checking the cache for null,
repopulating it as needed (maybe with delgates), etc.

If you were set on using outputcaching you'd put the outputcache into the
multimedia control, not the ASPX, & use one of the varyby* attributes. But
I
think that'll prove more trouble than it's worth in this situation.

--
Ben Strackany
www.developmentnow.com

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


"greg" <greg_platt (AT) hotmail (DOT) com> wrote in message
news:uQRa8bz1EHA.1144 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
I have an ASP app that i'm porting over ASP.Net

In an asp page i have many server.execute statements.

So in the asp page code i have something like this

%
session("objectid") = 1001778
server.execute("multimedia.aspx")

session("objectid") = 1001779
server.execute("multimedia.aspx")

session("objectid") = 1001899
server.execute("listrecords.aspx")

session("objectid") = 1001778
server.execute("multimedia.aspx")



%

Now i want only some code on the multimedia.aspx page to be cached as
some
of the queries on the page are dynamic.
However i also want the page caching to vary based upon the objectid
number
in the session variable. (BTW i am using a method that allows ASP
sessions
to be shared with ASP.net sessions).

what i don't quite understand is that if i set the OUTPUTCACHE at the top
of
page (in the .aspx file) to be cached and i use user controls in the ASPX
page for the dynamic queries is it possible to set the user controls so
they
are not cached or ....
can you only do it the other way round and have the cached portion in
user
controls.

An example of the multimedia.aspx file logic may read something like
this:

run query to get parameters for this multimedia object using the session
objectid variable as a parameter
output html (ie table with colours) based upon this query (this is what i
want to cache)

then run query to get a list of .gifs from the database (they can change
regularly so i want this dynamic)
output html (not cached)

--------------------------------------------------------------------------
------
The same multimedia.aspx can appear twice (with the same session objectid
as
a parameter) on the same ASP page. In each multimedia.aspx page that gets
passed a different session objectid the html output varys slightly (ie
table
colours etc.)


Thanks.















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

Default Re: Caching Advice Required - 12-01-2004 , 02:48 PM



Yeah, anything you cache will cache the stuff inside it. So you're better
off leaving the main ASPX uncached.

---aspx (not cached)
-- some queries
-- multimedia control (cached)
-- some queries
-- multimedia control (cached)
-- some queries
-- listrecords control (not cached)
-- some queries
-- multimedia control (cached)
--

After looking at your code again, I realize you don't have to use user
controls, since you're doing server.execute. Which if it works for you, is
probably ok (although user controls may perform better under load).

If you're just concerned about performance, you could change multimedia.aspx
to cache the database results, & leave the HTML generation alone. So in
multimedia.aspx whenever you called the database you could first see if the
dataset was in the cache. If it was't, you'd call the database, get back the
dataset, store it in the cache w/ a key associated with the dataset (e.g.
the objectid), and then use the dataset to draw html, whatever. Kinda like
this:

<%
string strObjectID = Session("ObjectID")
DataSet dsObject = Cache.Get("firstdataset"+strObjectID)
if (dsObject==null) {
// not in cache
// query the database, get back ds & store back in cache
Cache.Insert("firstdataset"+strObjectID, dsObject);
}
// use ds to generate some html, whatever
if (dsObject.RecordCount==1) {
DataSet dsTmp = Cache.Get("seconddataset"+strObjectID)
if (dsTmp==null) {
// not in cache
// query the database, get back ds & store back in cache
Cache.Insert("seconddataset"+strObjectID, dsTmp);
// draw some html
}
else {
DataSet dsTmp = Cache.Get("thirddataset"+strObjectID)
if (dsTmp==null) {
// not in cache
// query the database, get back ds & store back in cache
Cache.Insert("thirddataset"+strObjectID, dsTmp);
// draw some html
}
%>

That would be easier. If you really want to cache the HTML also, you would
need to store the HTML into a big string, & cache that string. Like

<%
string strObjectID = Session("ObjectID")
string strHTML = Cache.Get("html" + strObjectID)
if (strHTML==null) {
// not cached, need to build the HTML
strHTML = ""
strHTML += "<b>some html</b>"
// call the database
foreach(datarowview drv in DataSet.Tables[0].DefaultView) {
strHTML += "some more html" + drv["somefield"]
}
// cache html
Cache.Insert("html" + strObjectID, strHTML)
}
// output html
Response.Write(strHTML)
%>

But I don't think it's worth it...I'd suggest caching the database results
first, see how that works out.

FYI, using outputcache works easily when you have values in the querystring
you can use to distinguish between versions (e.g.
"multimedia.aspx?ObjectID=6561526"). Or if you're using user controls, you
can stick outputcache inside them & have them differentiate on querystring,
browser type, ID (i.e. the ID of the user control). There is also
VaryByCustom where you can do some custom coding for caching, but it may not
work out in your situation.

Good luck, lmk how it works out or if you have further questions. The
ASP.NET QuickStart has some good, easy caching examples. Or google.

--
Ben Strackany
www.developmentnow.com

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


"greg" <greg_platt (AT) hotmail (DOT) com> wrote

Quote:
Thanks,
That sounds good but what i don't quite understand is how i cache around
the
dynamic stuff.
For example in the multimedia.aspx

I run a query based upon parameter (session variable) then i output html
which you say i can cache.
Problem is that the dynamic queries appear in the page logic inbetween the
html i want to cache.

So i run the first query
then i might say something like this.
%
if object.recordcount=1 then
%><%=html%><%
// run dynamic query and output some dynamic html
%><%=morehtml%><%

else

%><%=html%><%
// run dynamic query here and output some dynamic html
%><%=morehtml%><%

end if
%

how do i easily cache the html around the dynamic queries?
With your method wouldn't i require lots of cache inserts for each block
of
html?

So ideally i would like to cache the aspx page but run some usercontrols
(with no caching) to output the dynamic stuff
I'm not sure if this is possible however.


"Ben Strackany" <infoNOSPAM (AT) developmentnow (DOT) nospam.com> wrote in message
news:up1W30z1EHA.1292 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
One easy way to handle all that would be to use data caching. Create a
"multimedia" user control that has an ObjectID property. The user
control's
code takes that objectid, calls the database, gets a dataset back,
builds
some HTML, & returns it. Your user control could cache the dataset e.g.

Cache.Insert("dataset"+this.ObjectID,dsTheResults)

Or it could build the HTML from the dataset & just cache the resulting
HTML

Cache.Insert("html"+this.ObjectID,strSomeHTML)

The code would do the normal stuff of checking the cache for null,
repopulating it as needed (maybe with delgates), etc.

If you were set on using outputcaching you'd put the outputcache into
the
multimedia control, not the ASPX, & use one of the varyby* attributes.
But
I
think that'll prove more trouble than it's worth in this situation.

--
Ben Strackany
www.developmentnow.com

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


"greg" <greg_platt (AT) hotmail (DOT) com> wrote in message
news:uQRa8bz1EHA.1144 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
I have an ASP app that i'm porting over ASP.Net

In an asp page i have many server.execute statements.

So in the asp page code i have something like this

%
session("objectid") = 1001778
server.execute("multimedia.aspx")

session("objectid") = 1001779
server.execute("multimedia.aspx")

session("objectid") = 1001899
server.execute("listrecords.aspx")

session("objectid") = 1001778
server.execute("multimedia.aspx")



%

Now i want only some code on the multimedia.aspx page to be cached as
some
of the queries on the page are dynamic.
However i also want the page caching to vary based upon the objectid
number
in the session variable. (BTW i am using a method that allows ASP
sessions
to be shared with ASP.net sessions).

what i don't quite understand is that if i set the OUTPUTCACHE at the
top
of
page (in the .aspx file) to be cached and i use user controls in the
ASPX
page for the dynamic queries is it possible to set the user controls so
they
are not cached or ....
can you only do it the other way round and have the cached portion in
user
controls.

An example of the multimedia.aspx file logic may read something like
this:

run query to get parameters for this multimedia object using the
session
objectid variable as a parameter
output html (ie table with colours) based upon this query (this is what
i
want to cache)

then run query to get a list of .gifs from the database (they can
change
regularly so i want this dynamic)
output html (not cached)


-------------------------------------------------------------------------
-
------
The same multimedia.aspx can appear twice (with the same session
objectid
as
a parameter) on the same ASP page. In each multimedia.aspx page that
gets
passed a different session objectid the html output varys slightly (ie
table
colours etc.)


Thanks.

















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.