469,930 Members | 1,726 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,930 developers. It's quick & easy.

Caching Output HTML

Just wondering what it would take to cache a copy of the output HTML from a
dynamically constructed aspx page before it is sent to the browser.

Reason being: the page is constructed of a few user controls, each of which
queries a SQL Server database for their content. The content is not likely
to change frequently at all - so I'd like a way to cache the final page upon
first request. Then subsequent requests are served from the cache - with no
need to do the expensive database queries on subsequent requests for the
cached page. Logic that updates the database would clear the cache so that
no stale data would exist in the cache.

1. How can I cache a copy of the page for future use?

2. How can I serve a subsequent request for the page directly from the
cache, rather than running the aspx logic?

Thanks.
Dec 1 '07 #1
3 1610
Use the cache directive in the "<%@Page .." header at the top of the aspx
page?

Something I'm missing or are you just not familiar with this feature of asp.net?

Dave Bush
http://blog.dmbcllc.com
Just wondering what it would take to cache a copy of the output HTML
from a dynamically constructed aspx page before it is sent to the
browser.

Reason being: the page is constructed of a few user controls, each of
which queries a SQL Server database for their content. The content is
not likely to change frequently at all - so I'd like a way to cache
the final page upon first request. Then subsequent requests are served
from the cache - with no need to do the expensive database queries on
subsequent requests for the cached page. Logic that updates the
database would clear the cache so that no stale data would exist in
the cache.

1. How can I cache a copy of the page for future use?

2. How can I serve a subsequent request for the page directly from the
cache, rather than running the aspx logic?

Thanks.

Dec 1 '07 #2
<snip>
Use the cache directive in the "<%@Page .." header at the top of the aspx
page?

Something I'm missing or are you just not familiar with this feature of
asp.net?
I am familiar with the cache directive. Perhaps I should have included a
couple of additional facts in my OP:

Most of the pages in the site never exist on disk. Instead, I plan to build
them programmatically from scratch, via HttpModule that builds and returns
the "page" to the user. I don't understand how ASP.NET implements caching
via the cache directive when serving up plain old aspx files - so I'm not
clear on how I can emulate that behavior in my HttpModule logic that builds
and returns these dynamic pages.

Until now the 1.1 system I have been working with inserts ascx user controls
into PlaceHolder controls in an aspx page that served as a template. But now
as we migrate to 3.5, I'm wanting to intercept the aspx requests as they
come in from the browser and do *everything* programmatically - including
(1) URL rewriting, (2) page construction, (3) retrieve the HTML of the final
page, (4) cache that HTML, (5) return the HTML to the requesting browser.
Subsequent requests for the same page would return the HTML from the cache.

Step 3 is what I am unclear on. How do I get the rendered HTML of a
dynamically constructed aspx before it is sent to the browser?

Thoughts? Considerations?

Thanks.
Dec 1 '07 #3
On Dec 1, 10:08 pm, "Smithers" <A...@B.comwrote:
<snip>
Use the cache directive in the "<%@Page .." header at the top of the aspx
page?
Something I'm missing or are you just not familiar with this feature of
asp.net?

I am familiar with the cache directive. Perhaps I should have included a
couple of additional facts in my OP:

Most of the pages in the site never exist on disk. Instead, I plan to build
them programmatically from scratch, via HttpModule that builds and returns
the "page" to the user. I don't understand how ASP.NET implements caching
via the cache directive when serving up plain old aspx files - so I'm not
clear on how I can emulate that behavior in my HttpModule logic that builds
and returns these dynamic pages.

Until now the 1.1 system I have been working with inserts ascx user controls
into PlaceHolder controls in an aspx page that served as a template. But now
as we migrate to 3.5, I'm wanting to intercept the aspx requests as they
come in from the browser and do *everything* programmatically - including
(1) URL rewriting, (2) page construction, (3) retrieve the HTML of the final
page, (4) cache that HTML, (5) return the HTML to the requesting browser.
Subsequent requests for the same page would return the HTML from the cache.

Step 3 is what I am unclear on. How do I get the rendered HTML of a
dynamically constructed aspx before it is sent to the browser?

Thoughts? Considerations?

Thanks.
Hi... Here is few Code exampls

protected void Page_Load(object sender, EventArgs e)
{
if (Session["PageOutPut"] != null)
{
if (Session["Counter"] == null)
{
Session["Counter"] = 0;
}
Session["Counter"] = (int)Session["Counter"] + 1;
string PageResult = (string)Session["PageOutPut"];
Response.Write(PageResult + (int)Session["Counter"]);
Response.End();
}
}

protected override void Render(HtmlTextWriter writer)
{
string PageResult = "";
if (Session["PageOutPut"] == null)
{
//get the html output and save it in session
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hWriter = new HtmlTextWriter(sw);
base.Render(hWriter);
PageResult = sb.ToString();
Session["PageOutPut"] = PageResult;
Response.Redirect(Page.Request.RawUrl);
}
}

Dec 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Captain Chaos | last post: by
10 posts views Thread by Jon Maz | last post: by
3 posts views Thread by Janaka | last post: by
1 post views Thread by Dave Bartlett | last post: by
2 posts views Thread by Welman Jordan | last post: by
2 posts views Thread by Mike Sobeiski | last post: by
10 posts views Thread by BillGatesFan | last post: by
2 posts views Thread by R-D-C | last post: by
5 posts views Thread by Erik Lautier | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.