By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Partial caching (a UserControl) with file dependency

P: n/a
Hello,
I want to partial cache by using a UserControl.

Now I have a file dependency.

In msdn I see it is not possible to do it the same way as in a page.

The only information is to create a file dependency and assign it to
Dependency property.

But UserControl has no Dependency Property.

What can I do.

Thank you for any help.

Rolf Welskes
Oct 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello Rolf,

As for the ASP.NET Output Cache, the UserControl(partial cache on page)
only provide limited cache dependency/policy support. You can find them
when typing the @OutputCache diretive in ascx template. e.g.

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="HelloWorldUC.ascx.cs" Inherits="usercontrols_HelloWorldUC" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>

In ASP.NET 2.0, usercontrol can be configured to cache upon the following
dependency:

** Timespan

**SqlDependency

**VaryByParam (querystring, control, form variables...)

**VaryByCustom(browser or custom setting...)

I've also check the FileDependency and the Dependency property you
mentioned, actually, there is programmatic interface for adding
filedependency for ASP.NET page's outputCache, it is done through
HttpResponse.AddXXXDependency methods. Unfortunately, so far the
UserControl hasn't provide this functionality, this is also limited due to
the ASP.NET output cache's granularity(output cache is based on a complete
page response).

BTW, would you tell me some detailed info or code logic about the page and
usercontrol that will want to use FileDependency cache? We can try to do
some further research to see whether we can find any other approach to
achive the same goal.

Please feel free to let me know if you have any other questions or concern
on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

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

Oct 18 '06 #2

P: n/a
Hello,
thank you for your informations.

What I want is very simple.

I have a page which is not cached.
In this page I have a usercontrol which is cached.
Total this means we have partial caching.

But, if the file data.txt is changed the cache of the usercontrol must get
invalid
because new calculation is neccessary.

I cannot cache the page because many calculations for each request are
neccessary.

One way could be because the page is not cached, to check the file in the
page code and
make the cache for the usercontrol invalid when the file has changed, but
how to make the cache of a user control invalid?

Thank you for any help.
Rolf Welskes


"Steven Cheng[MSFT]" <st*****@online.microsoft.comschrieb im Newsbeitrag
news:Zs**************@TK2MSFTNGXA01.phx.gbl...
Hello Rolf,

As for the ASP.NET Output Cache, the UserControl(partial cache on page)
only provide limited cache dependency/policy support. You can find them
when typing the @OutputCache diretive in ascx template. e.g.

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="HelloWorldUC.ascx.cs" Inherits="usercontrols_HelloWorldUC" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>

In ASP.NET 2.0, usercontrol can be configured to cache upon the following
dependency:

** Timespan

**SqlDependency

**VaryByParam (querystring, control, form variables...)

**VaryByCustom(browser or custom setting...)

I've also check the FileDependency and the Dependency property you
mentioned, actually, there is programmatic interface for adding
filedependency for ASP.NET page's outputCache, it is done through
HttpResponse.AddXXXDependency methods. Unfortunately, so far the
UserControl hasn't provide this functionality, this is also limited due to
the ASP.NET output cache's granularity(output cache is based on a complete
page response).

BTW, would you tell me some detailed info or code logic about the page and
usercontrol that will want to use FileDependency cache? We can try to do
some further research to see whether we can find any other approach to
achive the same goal.

Please feel free to let me know if you have any other questions or concern
on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

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

Oct 18 '06 #3

P: n/a
Hello Rolf,

Thanks for your reply and the further description.

For your scenario, you want the usercontrol's cache depend on a certain
external disk file. Since Usercontrol doesn't directly support
FileDependency in its cache dependency options, we need to look for other
means.

Based on my research, here is one possible solution to make UserControl
cached based on a certain file.

** You can set Usercontrol to use "VaryByCustom" cache and use
customstring as cache option. See the below msdn reference:

#How to: Cache Versions of a Page Using Custom Strings
http://msdn2.microsoft.com/en-us/library/5ecf4420.aspx
And in the overrided "GetVaryByCustomString" method, we use System.IO.File
class to query the certain file's "LastModified Date" attribute and return
this as the value of our customstring. e.g.

=========in global.asax===============
public override string GetVaryByCustomString(
HttpContext context,
string custom
)
{
if (custom == "filestring")
{
return
System.IO.File.GetLastWriteTimeUtc(@"D:\temp\file_ temp\test.log").Ticks.ToSt
ring();
}

return null;

}
===================================

the "filestring" correspond to the customstring in the below cache
directive of our usercontrol:
=====================
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="HelloWorldUC.ascx.cs" Inherits="usercontrols_HelloWorldUC" %>
<%@ OutputCache Duration="100" VaryByParam="None" VaryByCustom="filestring"
%>

==================

Please feel free to let me know if you have anything unclear.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 19 '06 #4

P: n/a
Hello,
thank you,
I have tested it.
It works,
BUT !!!!!!
if I have for example the cache time for the custom control on 6 hours.
And if the file is changed all 10 mintues,
we have after 6 hours 36 times the cached control in the cache,
because what we have is no dependency but a varybycustom,
means, the old cached value is not removed.

It's possible to do it, but is no good solution.

So, hope it will be solved in a service pack or next version.

Remark:
I have seen many cases where the basic functionality for a page is not
avaiblable for web custom control.
And this is bad, because many pages are build from web custom controls.
I have given a hint to microsoft in these other cases.

Thank you again.
Rolf Welskes
Oct 19 '06 #5

P: n/a
Thanks for your followup Rolf,

I agree with you, the customstring solution will cause many cached copy and
will add performance overhead when the usercontrol's content is large.

BTW, is your usercontrol only display one read-only data and will it need
to interact with other part of the page. If not, another approach is moved
the usercontrol's content into a separate page and embed this page in the
original page through html <iframeelement. Thus, you can use the
FileDependeny cache for that indiviual separate page.

Anyway, I also think it is a good idea that the usercontrol support more
featuers(not only about cache options) like the page supports. Actually,
the usercontrol has been enhanced much from 1.1 (e.g ascx usercontrol has
support design-time rendering in page designer, and can support inner html
template). Therefore, I would suggest you send this suggestion to the .net
feedback site so that the product team can hear on this.
#Visual Studio and .NET Framework Feedback
http://connect.microsoft.com/feedbac...spx?SiteID=210

Thanks again for your posting and the sincere feedback.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 20 '06 #6

P: n/a
Hello,
thank you for your work.
I hope we will have it in a future version.
Thank you again.
Rolf Welskes

"Steven Cheng[MSFT]" <st*****@online.microsoft.comschrieb im Newsbeitrag
news:cC**************@TK2MSFTNGXA01.phx.gbl...
Thanks for your followup Rolf,

I agree with you, the customstring solution will cause many cached copy
and
will add performance overhead when the usercontrol's content is large.

BTW, is your usercontrol only display one read-only data and will it need
to interact with other part of the page. If not, another approach is moved
the usercontrol's content into a separate page and embed this page in the
original page through html <iframeelement. Thus, you can use the
FileDependeny cache for that indiviual separate page.

Anyway, I also think it is a good idea that the usercontrol support more
featuers(not only about cache options) like the page supports. Actually,
the usercontrol has been enhanced much from 1.1 (e.g ascx usercontrol has
support design-time rendering in page designer, and can support inner html
template). Therefore, I would suggest you send this suggestion to the .net
feedback site so that the product team can hear on this.
#Visual Studio and .NET Framework Feedback
http://connect.microsoft.com/feedbac...spx?SiteID=210

Thanks again for your posting and the sincere feedback.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Oct 24 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.