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

Vary by custom

P: n/a
I am trying to "tune" some user controls in ASP.NET for optimal caching.

Is it possible to do a vary by param - on a Session Variable, so the page
caches when a Session variable stays the same, but refreshes when the
session changes?

thnx
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
What you could potentially do is set objects from within the ascx user
control, directly into the cache and set a manual file based dependancy.
all you need to to reset the cache is modify the file. (create an empty
file, set it as being a dependancy.. when you want to reset the cache.. just
change the time stamp)

Copying some text from msdn for user control caching
VaryByCustom
Any text that represents custom output caching requirements. If this
attribute is given a value of browser, the cache is varied by browser name
and major version information. If a custom string is entered, you must
override the HttpApplication.GetVaryByCustomString method in your
application's Global.asax file.
VaryByHeader
A semicolon-separated list of HTTP headers used to vary the output cache.
When this attribute is set to multiple headers, the output cache contains a
different version of the requested document for each specified header.
Note Setting the VaryByHeader attribute enables caching items in all
HTTP 1.1 caches, not just the ASP.NET cache. This attribute is not supported
for @ OutputCache directives in user controls.
VaryByParam
A semicolon-separated list of strings used to vary the output cache. By
default, these strings correspond to a query string value sent with GET
method attributes, or a parameter sent using the POST method. When this
attribute is set to multiple parameters, the output cache contains a
different version of the requested document for each specified parameter.
Possible values include none, *, and any valid query string or POST
parameter name.
CAUTION This attribute is required when you output cache ASP.NET pages.
It is required for user controls as well unless you have included a
VaryByControl attribute in the control's @ OutputCache directive. A parser
error occurs if you fail to include it. If you do not want to specify a
parameter to vary cached content, set the value to none. If you want to vary
the output cache by all parameter values, set the attribute to *.
VaryByControl
A semicolon-separated list of strings used to vary a user control's output
cache. These strings represent the ID property values of ASP.NET server
controls declared in the user control. For more information, see Caching
Portions of an ASP.NET Page.

--
Regards,
HD
Once a Geek.... Always a Geek
"Ryan Moore" <ry*******@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP12.phx.gbl...
I am trying to "tune" some user controls in ASP.NET for optimal caching.

Is it possible to do a vary by param - on a Session Variable, so the page
caches when a Session variable stays the same, but refreshes when the
session changes?

thnx

Nov 18 '05 #2

P: n/a
Ryan:

Your subject line just about gives you the answer. Use VaryByCustom in
the @OutputCache directive.

<%@ OutputCache Duration="30" VaryByParam="none"
VaryByCustom="MySpecialSessionVariable" %>

Then in global.asax, you need to overide GetVaryByCustomString:

public override string GetVaryByCustomString(
HttpContext context,
string arg)
{
string result = String.Empty;

if(arg == "MySpecialSessionVariable")
{
object o = Session["MySpecialSessionVariable"];
if(o != null)
{
result = o.ToString();
}
}
else
{
result = base.GetVaryByCustomString(context, arg);
}

return result;
}

On Tue, 27 Jan 2004 15:39:42 -0600, "Ryan Moore"
<ry*******@hotmail.com> wrote:
I am trying to "tune" some user controls in ASP.NET for optimal caching.

Is it possible to do a vary by param - on a Session Variable, so the page
caches when a Session variable stays the same, but refreshes when the
session changes?

thnx


--
Scott
http://www.OdeToCode.com
Nov 18 '05 #3

P: n/a
OK, Got that to work, now it seems that I'm having problems when I have
multiple controls loaded into a page, each with a seperate
"customcachestring".... is there anything I should know about this? when I
have 2 seperate user controls which use custom strings, only one of the
controls shows up on the page!

thnx
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:j4********************************@4ax.com...
Ryan:

Your subject line just about gives you the answer. Use VaryByCustom in
the @OutputCache directive.

<%@ OutputCache Duration="30" VaryByParam="none"
VaryByCustom="MySpecialSessionVariable" %>

Then in global.asax, you need to overide GetVaryByCustomString:

public override string GetVaryByCustomString(
HttpContext context,
string arg)
{
string result = String.Empty;

if(arg == "MySpecialSessionVariable")
{
object o = Session["MySpecialSessionVariable"];
if(o != null)
{
result = o.ToString();
}
}
else
{
result = base.GetVaryByCustomString(context, arg);
}

return result;
}

On Tue, 27 Jan 2004 15:39:42 -0600, "Ryan Moore"
<ry*******@hotmail.com> wrote:
I am trying to "tune" some user controls in ASP.NET for optimal caching.

Is it possible to do a vary by param - on a Session Variable, so the page
caches when a Session variable stays the same, but refreshes when the
session changes?

thnx


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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.