473,387 Members | 1,621 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,387 software developers and data experts.

caching user control output, at runtime, how to?

Hello,

I met with a tough problem when making my pages. Please help. To
make the problem short, i write down what i want here first, and then
explain my situation in details.

How can I acchieve this:

Only one Page_Load, and then the output of the control is cached
within the Cache[], accessible via a programatically generated
cachekey.

The cache duration is adjustable at RUN TIME.
------------------------------------------------------
My situation:

I wanna make a web page which contains several dynamically loaded
user controls. I do so by using a placeholder control and load some
controls into that holder in the Page_Load event.

Approach 1:
I would like to cache some certain HTML output of the dynamically
loaded controls. I know that using the @ OutputCache directive can
help me do so. However, that's too limited, since the caching
duration has been deternmined at design time, NOT AT RUN TIME!
I know that there's a VaryByCustom parameter, which might be of
help. But I even DO NOT want to specify this directive in the code at
all! I hope that I can design to cache or not cache at run time.

Approach 2:
My another approach is to cache the output stream in the Render
event handler. I attempt to use an StringWriter to catch the output.

TextWriter tempWriter = new StringWriter();
base.Render(new HtmlTextWriter(tempWriter));
_cachedOutput = tempWriter.ToString();

Cache.Insert(CacheKey, _cachedOutput, null,
DateTime.Now.AddSeconds(_cacheTime), TimeSpan.Zero);

However, the codes in the Page_Load of the control still get
executed--I heavily query the database. Thus there's little help
to reduce the CPU load of the server, since the database query
routine still runs.

How to take both the advantage of approach 1 that Page_Load only
runs once, and the advantage of approach 2 that the caching time
is adjustable?

W. Jordan
Nov 18 '05 #1
2 1331
Hi Welman:

The Cache property of the Response object is an instance of
HttpCachePolicy . With the methods and properties of the
HttpCachePolicy object you can programmatically control all of the
cache settings at runtime ins tread of design time.

HTH,

--
Scott
http://www.OdeToCode.com

On Wed, 26 May 2004 18:17:01 +0800, "Welman Jordan"
<_n**************@163.com> wrote:
Hello,

I met with a tough problem when making my pages. Please help. To
make the problem short, i write down what i want here first, and then
explain my situation in details.

How can I acchieve this:

Only one Page_Load, and then the output of the control is cached
within the Cache[], accessible via a programatically generated
cachekey.

The cache duration is adjustable at RUN TIME.


Nov 18 '05 #2
Hello Scott,

Thanks for telling me that.
But what I what is the individual control over the cache
for my user controls, not a page.

It seems that the HttpCachePolicy object can not be of
help.

W. Jordan

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:sf********************************@4ax.com...
Hi Welman:

The Cache property of the Response object is an instance of
HttpCachePolicy . With the methods and properties of the
HttpCachePolicy object you can programmatically control all of the
cache settings at runtime ins tread of design time.

HTH,

--
Scott
http://www.OdeToCode.com

On Wed, 26 May 2004 18:17:01 +0800, "Welman Jordan"
<_n**************@163.com> wrote:
Hello,

I met with a tough problem when making my pages. Please help. To
make the problem short, i write down what i want here first, and then
explain my situation in details.

How can I acchieve this:

Only one Page_Load, and then the output of the control is cached
within the Cache[], accessible via a programatically generated
cachekey.

The cache duration is adjustable at RUN TIME.

Nov 18 '05 #3

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

Similar topics

1
by: Stewart | last post by:
Hi all, hoping one of you may be able to throw up an idea on the following. I have an asp.net page with a drop-down and a user control inside. The user control should be cached in one way or...
3
by: George Ter-Saakov | last post by:
I have a Response.Filter set. Will it affect caching (by ASP.NET) of my page? Basically the question is caching happens before or after filtering? My understanding ,because partial caching...
0
by: Martin | last post by:
Hi. I had a very frustrating afternoon and evening but I have got it all under control now so all of a sudden I am in a good mood. I want to share some insights on output caching with you lot. ...
3
by: Janaka | last post by:
Hi All, I'm having a problem with Page Output caching on a page that contains a DataGrid. Basically the page pulls up some data for sales information from the DB. Some of this has to be...
0
by: Jeff Schaefer | last post by:
What I want to know is this: Is it possible to programmatically manipulate a custom property of a user control for which <%@ OutputCache ... > has been included? If so, then how? My brief code is...
3
by: DC | last post by:
Hi, (ASP.Net 1.1) is it possible to (programmatically and globally) deactivate page fragment caching? We have only two scenarios, development stage where we want caching off and testing where we...
0
by: Chris | last post by:
I've been playing with the fragment caching and it seems to work fine. I have a user control that I set to cache. The user control has a few text boxes and a drop down list box populated from a...
1
by: Ben Fidge | last post by:
What are best practices for page output caching on pages that are dynamically generated from database tables. Our site has left-hand navigation that is comprised of dynamically generated menus...
1
by: Ben Fidge | last post by:
I've got a User Control that renders site navigation from a database. For some reason, when using Output Caching, none of my LinkButtons fire their PostBack events. The declaration in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.