Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Speeding Up with Controls and Caching?

Reply
Thread Tools

Speeding Up with Controls and Caching?

 
 
Erik Lautier
Guest
Posts: n/a
 
      01-11-2007
I have two subroutines that are running on virtually every page of my
site; it's an if/then/else situation where one runs if the user is
registered and the other runs if the user is a guest. I have two
questions:

1. Since they're on virtually every page, I know that registering them
in a .ascx control will simplify things, but will it actually speed my
pages up?

2. If I go ahead with #1, can I cache the control page and get the
speed boost I'm looking for?

Any caveats about this? Thanks a lot.

 
Reply With Quote
 
 
 
 
Aidy
Guest
Posts: n/a
 
      01-11-2007
> 1. Since they're on virtually every page, I know that registering them
> in a .ascx control will simplify things, but will it actually speed my
> pages up?


I wouldn't think so, it just makes it easier to manage.

> 2. If I go ahead with #1, can I cache the control page and get the
> speed boost I'm looking for?


Caching can help but remember that you cache the *output* of the control.
Output caching only works when the resulting HTML never changes. If you
control prints "Welcome back <username>" if you are logged in and "Click
here to sign in" if you are not then such a control is not suitable for
output caching.


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      01-11-2007
that's not true. Outputcaching allows for variances.

In your case you would use the VaryByCustom property of the OutputCache
control...it's quite simple.

<%@ OutputCache duration="600" VaryByCustom="LoggedIn" VaryByParam="None" %>

and in your global.asax, you'd do:

public override string GetVaryByCustomString(HttpContext context, string
customString)
{
switch(customString)
{
case " LoggedIn":
return (CurrentUserIsLoggedIn) ? "logged" : "notlogged"
break;
}
base.GetVaryByCustomString(context, customString);
}


Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/


"Aidy" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
>> 1. Since they're on virtually every page, I know that registering them
>> in a .ascx control will simplify things, but will it actually speed my
>> pages up?

>
> I wouldn't think so, it just makes it easier to manage.
>
>> 2. If I go ahead with #1, can I cache the control page and get the
>> speed boost I'm looking for?

>
> Caching can help but remember that you cache the *output* of the control.
> Output caching only works when the resulting HTML never changes. If you
> control prints "Welcome back <username>" if you are logged in and "Click
> here to sign in" if you are not then such a control is not suitable for
> output caching.
>


 
Reply With Quote
 
Aidy
Guest
Posts: n/a
 
      01-11-2007
Interesting, I'll need to play with that. I knew about the VaryByParam but
not ByCustom.

"Karl Seguin" <(E-Mail Removed) > wrote in
message news:(E-Mail Removed)...
> that's not true. Outputcaching allows for variances.
>
> In your case you would use the VaryByCustom property of the OutputCache
> control...it's quite simple.
>
> <%@ OutputCache duration="600" VaryByCustom="LoggedIn" VaryByParam="None"
> %>
>
> and in your global.asax, you'd do:
>
> public override string GetVaryByCustomString(HttpContext context, string
> customString)
> {
> switch(customString)
> {
> case " LoggedIn":
> return (CurrentUserIsLoggedIn) ? "logged" : "notlogged"
> break;
> }
> base.GetVaryByCustomString(context, customString);
> }
>
>
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
>
> "Aidy" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>>> 1. Since they're on virtually every page, I know that registering them
>>> in a .ascx control will simplify things, but will it actually speed my
>>> pages up?

>>
>> I wouldn't think so, it just makes it easier to manage.
>>
>>> 2. If I go ahead with #1, can I cache the control page and get the
>>> speed boost I'm looking for?

>>
>> Caching can help but remember that you cache the *output* of the control.
>> Output caching only works when the resulting HTML never changes. If you
>> control prints "Welcome back <username>" if you are logged in and "Click
>> here to sign in" if you are not then such a control is not suitable for
>> output caching.
>>

>



 
Reply With Quote
 
Erik Lautier
Guest
Posts: n/a
 
      01-11-2007
Thanks to both of you; the only thing is that I have a remote host and
have never messed with global.asax - there are a numbere of files that
they administer, and I assume this is one of them. Would I just put
the below code in every .aspx page then?

Karl Seguin wrote:
> that's not true. Outputcaching allows for variances.
>
> In your case you would use the VaryByCustom property of the OutputCache
> control...it's quite simple.
>
> <%@ OutputCache duration="600" VaryByCustom="LoggedIn" VaryByParam="None" %>
>
> and in your global.asax, you'd do:
>
> public override string GetVaryByCustomString(HttpContext context, string
> customString)
> {
> switch(customString)
> {
> case " LoggedIn":
> return (CurrentUserIsLoggedIn) ? "logged" : "notlogged"
> break;
> }
> base.GetVaryByCustomString(context, customString);
> }
>
>
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
>
> "Aidy" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> >> 1. Since they're on virtually every page, I know that registering them
> >> in a .ascx control will simplify things, but will it actually speed my
> >> pages up?

> >
> > I wouldn't think so, it just makes it easier to manage.
> >
> >> 2. If I go ahead with #1, can I cache the control page and get the
> >> speed boost I'm looking for?

> >
> > Caching can help but remember that you cache the *output* of the control.
> > Output caching only works when the resulting HTML never changes. If you
> > control prints "Welcome back <username>" if you are logged in and "Click
> > here to sign in" if you are not then such a control is not suitable for
> > output caching.
> >


 
Reply With Quote
 
Karl Seguin [MVP]
Guest
Posts: n/a
 
      01-11-2007
No, GetVaryByCustomString must be in global.asax (annoyingly so).

You would place the OutputCache tag in your .ascx which displays your two
cases.


Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


"Erik Lautier" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Thanks to both of you; the only thing is that I have a remote host and
> have never messed with global.asax - there are a numbere of files that
> they administer, and I assume this is one of them. Would I just put
> the below code in every .aspx page then?
>
> Karl Seguin wrote:
>> that's not true. Outputcaching allows for variances.
>>
>> In your case you would use the VaryByCustom property of the OutputCache
>> control...it's quite simple.
>>
>> <%@ OutputCache duration="600" VaryByCustom="LoggedIn" VaryByParam="None"
>> %>
>>
>> and in your global.asax, you'd do:
>>
>> public override string GetVaryByCustomString(HttpContext context, string
>> customString)
>> {
>> switch(customString)
>> {
>> case " LoggedIn":
>> return (CurrentUserIsLoggedIn) ? "logged" : "notlogged"
>> break;
>> }
>> base.GetVaryByCustomString(context, customString);
>> }
>>
>>
>> Karl
>> --
>> http://www.openmymind.net/
>> http://www.fuelindustries.com/
>>
>>
>> "Aidy" <(E-Mail Removed)> wrote in message
>> news(E-Mail Removed)...
>> >> 1. Since they're on virtually every page, I know that registering
>> >> them
>> >> in a .ascx control will simplify things, but will it actually speed my
>> >> pages up?
>> >
>> > I wouldn't think so, it just makes it easier to manage.
>> >
>> >> 2. If I go ahead with #1, can I cache the control page and get the
>> >> speed boost I'm looking for?
>> >
>> > Caching can help but remember that you cache the *output* of the
>> > control.
>> > Output caching only works when the resulting HTML never changes. If
>> > you
>> > control prints "Welcome back <username>" if you are logged in and
>> > "Click
>> > here to sign in" if you are not then such a control is not suitable for
>> > output caching.
>> >

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
I need help speeding up an app that reads football scores and generates rankings jocknerd Python 4 05-02-2007 05:09 PM
Speeding up programs AND background tasks? Mama Bear Computer Support 7 03-02-2006 03:34 AM
speeding up data transfer? Devin Panchal Wireless Networking 1 09-06-2004 05:46 PM
Cleaning and speeding up? Samantha Computer Information 5 02-21-2004 06:55 PM



Advertisments