473,406 Members | 2,404 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,406 software developers and data experts.

Fragmented Cache

A.M
Hi,

How can I change the duration of user control's cache inside asp.net's C#
code?

Any help would be apprecited,
Alan
Nov 18 '05 #1
7 1507
NOTE: I am going to hit the entire topic, so you can see both ways. What you
are asking is the second way.

You can do this declaratively, which is, by far the easiest:

<%@ OutputCache Duration="60" VaryByParam="None" %>

The VaryByParam is most easily implemented by adding properties to the
CodeBehind of your user control. To set parameters in CodeBehind of your
ASPX page, you will have to reference the control. For example, you drag a
control called TopMenu on your ASPX page creating topMenu1

protected TopMenu topMenu1;

You can then set properties in CodeBehind. For example, you have a UserName
property:

topMenu1.UserName = User.Identity.Name;

To set cache programatically use the HttpResponse.Cache Property. This is
from the help file:

Response.Cache.SetExpires(DateTime.Now.AddSeconds( 60));
Response.Cache.SetCacheability(HttpCacheability.Pu blic);
Response.Cache.SetValidUntilExpires(false);
Response.Cache.VaryByParams["Category"] = true;

if (Response.Cache.VaryByParams["Category"])
{
//...
}
A couple of links
http://authors.aspalliance.com/aspxt...lassCache.aspx
- overview
http://support.microsoft.com/default...b;en-us;323290 - more detail
instructions

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"A.M" <IH*******@sapm123.com> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I change the duration of user control's cache inside asp.net's C#
code?

Any help would be apprecited,
Alan

Nov 18 '05 #2
A.M
Thank you for reply.

I know how to setup user-control's cache parameters during design time.

Response.Cache has nothing to do with user-control caching. Response.Cache
defines how the entire page is being cached at *client browser* 's cache as
opposed to user-control's cach which defines how the user-control's output
is being cached on *web server*'s memory !!

I am looking for some way to change user-control's cache parameters during
design time.

Alan

"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
NOTE: I am going to hit the entire topic, so you can see both ways. What you are asking is the second way.

You can do this declaratively, which is, by far the easiest:

<%@ OutputCache Duration="60" VaryByParam="None" %>

The VaryByParam is most easily implemented by adding properties to the
CodeBehind of your user control. To set parameters in CodeBehind of your
ASPX page, you will have to reference the control. For example, you drag a
control called TopMenu on your ASPX page creating topMenu1

protected TopMenu topMenu1;

You can then set properties in CodeBehind. For example, you have a UserName property:

topMenu1.UserName = User.Identity.Name;

To set cache programatically use the HttpResponse.Cache Property. This is
from the help file:

Response.Cache.SetExpires(DateTime.Now.AddSeconds( 60));
Response.Cache.SetCacheability(HttpCacheability.Pu blic);
Response.Cache.SetValidUntilExpires(false);
Response.Cache.VaryByParams["Category"] = true;

if (Response.Cache.VaryByParams["Category"])
{
//...
}
A couple of links
http://authors.aspalliance.com/aspxt...lassCache.aspx - overview
http://support.microsoft.com/default...b;en-us;323290 - more detail instructions

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"A.M" <IH*******@sapm123.com> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
Hi,

How can I change the duration of user control's cache inside asp.net's C# code?

Any help would be apprecited,
Alan


Nov 18 '05 #3
Hi Alan,

As for the UserControl's output Control, based on my research, we can only
set its output cache declartively at desige time either use the <%@
OutputCache Duration="60" VaryByParam="state" %>( in ascx file)
or the following meta attribute
[PartialCaching(10, "state", null, null)]
public class CacheUC : System.Web.UI.UserControl
in UserControl's code behind class, but both of them are set at designtime
rather than runtime.

As for the Response.Cache.XXX methoed by Cowboy, they're also ok for
caching on serverside(not only at clientside) as long as we set the
cacheability as server, for example:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 10));
Response.Cache.VaryByParams["state"] = true;
Response.Cache.SetCacheability(System.Web.HttpCach eability.Server);
...
#don't turn on the Page's trace, that'll cause the programmatically cache
not work

But this is only for caching the whole asp.net web page, not for a partion
of page(a usercontrol).
So to cache a UserControl we have to make the outputcache setting at
designtime.
If you still have anything unclear, please feel free to post here. Thanks.
Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #4
A.M

Thank you Steven for help.

Your reply clarified important points for me.

So if I need to change usercontrol's cache at design time, the only option
that I have is opening the ascx file as a text file, change the cache
parameter on top of the page and write it back into the hard drive. I have
to give wite permission to certain folders to ASPNET user. Do you think that
will work?

Thank you,
Alan



"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:wK**************@cpmsftngxa10.phx.gbl...
Hi Alan,

As for the UserControl's output Control, based on my research, we can only
set its output cache declartively at desige time either use the <%@
OutputCache Duration="60" VaryByParam="state" %>( in ascx file)
or the following meta attribute
[PartialCaching(10, "state", null, null)]
public class CacheUC : System.Web.UI.UserControl
in UserControl's code behind class, but both of them are set at designtime rather than runtime.

As for the Response.Cache.XXX methoed by Cowboy, they're also ok for
caching on serverside(not only at clientside) as long as we set the
cacheability as server, for example:

private void Page_Load(object sender, System.EventArgs e)
{
Response.Cache.SetExpires(DateTime.Now.AddSeconds( 10));
Response.Cache.VaryByParams["state"] = true;
Response.Cache.SetCacheability(System.Web.HttpCach eability.Server);
..
#don't turn on the Page's trace, that'll cause the programmatically cache
not work

But this is only for caching the whole asp.net web page, not for a partion
of page(a usercontrol).
So to cache a UserControl we have to make the outputcache setting at
designtime.
If you still have anything unclear, please feel free to post here. Thanks.
Steven Cheng
Microsoft Online Support

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

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Hi Alan,

Do you mean that you'd like to use the IO api in asp.net web application to
modify the aspx or ascx file 's content so as to modify the @Outputcache
diretive?

If so , I don't think this is good approach and don't recommend you do
that because:
1. This means will need us to grant the file permission to the aspnet
process account. This is not quite reasonable

2. The ASP.NET runtime will monitor the web application's folder , if the
source file is modified , at runtime ,the certain requested web page(if not
the first time be requested) will be recompiled. And there is a limitation
setting in the machine.config determine that when the modify time exceed
the limitation, the whole application(appdomain) will restart. I don't
think this is what you want to see, yes?

Please have a consider at the above things. If you have anything unclear,
please feel free to post here. Thanks.

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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6
A.M
Thank you for suggestion.

I am considering to write a helper executable that application administrator
can run and it applies cache settings(stored in separated config file) to
ascx files. It shouldn't take much time. so web application won't get
restarted.

Do you think this approach works?

Alan
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:uW*************@cpmsftngxa10.phx.gbl...
Hi Alan,

Do you mean that you'd like to use the IO api in asp.net web application to modify the aspx or ascx file 's content so as to modify the @Outputcache
diretive?

If so , I don't think this is good approach and don't recommend you do
that because:
1. This means will need us to grant the file permission to the aspnet
process account. This is not quite reasonable

2. The ASP.NET runtime will monitor the web application's folder , if the
source file is modified , at runtime ,the certain requested web page(if not the first time be requested) will be recompiled. And there is a limitation
setting in the machine.config determine that when the modify time exceed
the limitation, the whole application(appdomain) will restart. I don't
think this is what you want to see, yes?

Please have a consider at the above things. If you have anything unclear,
please feel free to post here. Thanks.

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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7
Hi Alan,

Thanks for the followup. I still think there will occur some unexpected
issues if you manually modify the aspx or ascx source at runtime since the
asp.net runtime will monitor the applications' folders and files and will
restart the applicaiton no matter your modification will take much time or
not. Anyway, this may work if you don't frequently change the ascx file
and I think a simple test will be more helpful. Thanks.
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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #8

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

Similar topics

1
by: Janneke | last post by:
Hi All, I created a script to defragment a database. To test this script I need a fragmented database. Does anyone knows a way to fragment a database easily? Thanks in advanched, Janneke
3
by: kalpesh.shah | last post by:
kalpesh.s...@gmail.com Feb 1, 6:50 am show options Newsgroups: comp.databases.informix From: kalpesh.s...@gmail.com - Find messages by this author Date: 1 Feb 2005 06:50:21 -0800 Local:...
3
by: martin | last post by:
Hi, I am storing a dataset in cache, which is happening fine. I can easily retrive it at postback from the cache, cast it to a dataset and reuse it. However I have specified that the cache...
5
by: Darrel | last post by:
I thought this warranted a new thread. Yesterday I asked about access relatively static content...is it better to read from the DB, or just grab a text file. It was suggested that I use the DB...
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...
6
by: Tom | last post by:
Given: A binary data file of records. Task: Random access using seekg(). I've never found any documentation stating that the offset from begin file marker is safe on a fragmented file. I've...
0
by: mateipuiu | last post by:
When a try to run a client build on 2005, which uses the Microsoft.ApplicationBlocks.Cache.dll reference, when using a Microsoft.ApplicationBlocks.Cache.dll created on Debug mode, the client works...
5
by: Stan SR | last post by:
Hi, Some newbie questions.. :-) First, what is the namespace to use for the Cache class ? When I use this bit of code I get an error if (Cache==null) Cache.Insert("myUserList",userlist);...
0
by: =?Utf-8?B?YmlqYXk=?= | last post by:
The type initializer for 'Microsoft.ApplicationBlocks.Cache.CacheService' threw an exception. We migrated our windows application from 1.1 to 2.0. The debug and Release mode of the application...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.