Speeding Up with Controls and Caching?

Discussion in 'ASP .Net' started by Erik Lautier, Jan 11, 2007.

  1. Erik Lautier

    Erik Lautier Guest

    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.
     
    Erik Lautier, Jan 11, 2007
    #1
    1. Advertising

  2. Erik Lautier

    Aidy Guest

    > 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.
     
    Aidy, Jan 11, 2007
    #2
    1. Advertising

  3. Erik Lautier

    Karl Seguin Guest

    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" <> wrote in message
    news:p...
    >> 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.
    >
     
    Karl Seguin, Jan 11, 2007
    #3
  4. Erik Lautier

    Aidy Guest

    Interesting, I'll need to play with that. I knew about the VaryByParam but
    not ByCustom.

    "Karl Seguin" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:p...
    >>> 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.
    >>

    >
     
    Aidy, Jan 11, 2007
    #4
  5. Erik Lautier

    Erik Lautier Guest

    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" <> wrote in message
    > news:p...
    > >> 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.
    > >
     
    Erik Lautier, Jan 11, 2007
    #5
  6. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    >> news:p...
    >> >> 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.
    >> >

    >
     
    Karl Seguin [MVP], Jan 11, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spamtrap

    Need some hints on speeding up

    Spamtrap, Aug 11, 2004, in forum: Perl
    Replies:
    1
    Views:
    378
    Jim Gibson
    Aug 12, 2004
  2. Hypo
    Replies:
    6
    Views:
    448
  3. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    816
    Troy Simpson
    Jan 19, 2004
  4. jocknerd
    Replies:
    4
    Views:
    258
    Gabriel Genellina
    May 2, 2007
  5. JimLad
    Replies:
    3
    Views:
    934
    JimLad
    Jan 21, 2010
Loading...

Share This Page