User Control, @OutputCache, and varying the cache by property value

Discussion in 'ASP .Net' started by Tom Kiefer, Jan 24, 2004.

  1. Tom Kiefer

    Tom Kiefer Guest

    Question:
    If I have an ASP.NET User Control which defines/exposes a property that the
    page can use to specify a mode or data subset for the control to use, is
    there a way to tell the @OutputCache directive to vary its cache based on
    that property value?

    I.e., I have:

    <my:control runat="server" id="mcOne" Flag="One" />
    <my:control runat="server" id="mcTwo" Flag="Two" />

    where Flag is a public property of the code-behind class (whose value
    affects the display output), and I want the Flag="One" instance to
    output-cache separately from the Flag="Two" instance.

    So far, the control seems to output-cache only one version of the control,
    and all successive displays of the control use that cached version,
    regardless of the Flag attribute value.

    Other notes:

    The @OutputCache directive's VaryByParam attribute works only with GET and
    POST values. (I did try VaryByParam="Flag" anyway, to no effect.)

    Setting the @OutputCache directive's Shared attribute to "False" solves the
    problem (by causing each usage of the control to cache separately), but has
    the additional effect of requiring separate initial-loads and caches for
    each page on which the control appears. Since I currently only have two or
    three possible values of the Flag attribute, but these controls may appear
    on many pages (and there is some work invovled in the initial load of the
    data for this control), this is not ideal.

    There doesn't seem to be any sort of VaryByProperty attribute for
    @OutputCache (which surprises me). So...

    Any other ideas?

    - Tom Kiefer
    thogek @ earthlink . net
    Tom Kiefer, Jan 24, 2004
    #1
    1. Advertising

  2. Tom Kiefer

    Anders Borum Guest

    Have you looked at VaryByCustom?

    --
    venlig hilsen / with regards
    anders borum
    --
    Anders Borum, Jan 24, 2004
    #2
    1. Advertising

  3. Tom Kiefer

    Tom Kiefer Guest

    Yes, but I'm unclear on how that construct would be able to access anything
    specific to the control being cached.

    From
    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconOutputCache.asp
    and
    http://msdn.microsoft.com/library/e...pplicationClassGetVaryByCustomStringTopic.asp, I
    see VaryByCustom allowing me to specify arbitrary rules that can act on the
    HttpContext of the current request, but not on details within the control
    itself (such as the value of a given property).

    Unless I'm missing something....

    - Tom Kiefer
    thogek @ earthlink . net


    "Anders Borum" <> wrote in message
    news:...
    > Have you looked at VaryByCustom?
    >
    > --
    > venlig hilsen / with regards
    > anders borum
    > --
    >
    Tom Kiefer, Jan 24, 2004
    #3
  4. Tom Kiefer

    Tom Kiefer Guest

    I'm guessing from the lack of response that there's no ready way to do what
    I'm looking for. :-(

    If anyone from Microsoft is reading this, is there any indication that any
    future versions of ASP.NET might support what I attempt to describe below?

    - Tom Kiefer
    thogek @ earthlink . net


    "Tom Kiefer" <> wrote in message
    news:...
    > Question:
    > If I have an ASP.NET User Control which defines/exposes a property that

    the
    > page can use to specify a mode or data subset for the control to use, is
    > there a way to tell the @OutputCache directive to vary its cache based on
    > that property value?
    >
    > I.e., I have:
    >
    > <my:control runat="server" id="mcOne" Flag="One" />
    > <my:control runat="server" id="mcTwo" Flag="Two" />
    >
    > where Flag is a public property of the code-behind class (whose value
    > affects the display output), and I want the Flag="One" instance to
    > output-cache separately from the Flag="Two" instance.
    >
    > So far, the control seems to output-cache only one version of the control,
    > and all successive displays of the control use that cached version,
    > regardless of the Flag attribute value.
    >
    > Other notes:
    >
    > The @OutputCache directive's VaryByParam attribute works only with GET and
    > POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
    >
    > Setting the @OutputCache directive's Shared attribute to "False" solves

    the
    > problem (by causing each usage of the control to cache separately), but

    has
    > the additional effect of requiring separate initial-loads and caches for
    > each page on which the control appears. Since I currently only have two

    or
    > three possible values of the Flag attribute, but these controls may appear
    > on many pages (and there is some work invovled in the initial load of the
    > data for this control), this is not ideal.
    >
    > There doesn't seem to be any sort of VaryByProperty attribute for
    > @OutputCache (which surprises me). So...
    >
    > Any other ideas?
    >
    > - Tom Kiefer
    > thogek @ earthlink . net
    >
    >
    Tom Kiefer, Feb 8, 2004
    #4
  5. Just a guess-- Have you looked at VaryByControl?

    http://msdn.microsoft.com/library/d...pleversionsofusercontrolbasedonparameters.asp

    Thanks,

    Eric Lawrence
    Program Manager
    Assistance and Worldwide Services

    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Tom Kiefer" <> wrote in message
    news:OML$...
    > I'm guessing from the lack of response that there's no ready way to do

    what
    > I'm looking for. :-(
    >
    > If anyone from Microsoft is reading this, is there any indication that any
    > future versions of ASP.NET might support what I attempt to describe below?
    >
    > - Tom Kiefer
    > thogek @ earthlink . net
    >
    >
    > "Tom Kiefer" <> wrote in message
    > news:...
    > > Question:
    > > If I have an ASP.NET User Control which defines/exposes a property that

    > the
    > > page can use to specify a mode or data subset for the control to use, is
    > > there a way to tell the @OutputCache directive to vary its cache based

    on
    > > that property value?
    > >
    > > I.e., I have:
    > >
    > > <my:control runat="server" id="mcOne" Flag="One" />
    > > <my:control runat="server" id="mcTwo" Flag="Two" />
    > >
    > > where Flag is a public property of the code-behind class (whose value
    > > affects the display output), and I want the Flag="One" instance to
    > > output-cache separately from the Flag="Two" instance.
    > >
    > > So far, the control seems to output-cache only one version of the

    control,
    > > and all successive displays of the control use that cached version,
    > > regardless of the Flag attribute value.
    > >
    > > Other notes:
    > >
    > > The @OutputCache directive's VaryByParam attribute works only with GET

    and
    > > POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
    > >
    > > Setting the @OutputCache directive's Shared attribute to "False" solves

    > the
    > > problem (by causing each usage of the control to cache separately), but

    > has
    > > the additional effect of requiring separate initial-loads and caches for
    > > each page on which the control appears. Since I currently only have two

    > or
    > > three possible values of the Flag attribute, but these controls may

    appear
    > > on many pages (and there is some work invovled in the initial load of

    the
    > > data for this control), this is not ideal.
    > >
    > > There doesn't seem to be any sort of VaryByProperty attribute for
    > > @OutputCache (which surprises me). So...
    > >
    > > Any other ideas?
    > >
    > > - Tom Kiefer
    > > thogek @ earthlink . net
    > >
    > >

    >
    >
    Eric Lawrence [MSFT], Feb 9, 2004
    #5
  6. Tom Kiefer

    Tom Kiefer Guest

    According to
    http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconOutputCache.asp
    and
    http://msdn.microsoft.com/library/e...pleversionsofusercontrolbasedonparameters.asp,
    this sounds like VaryByControl directs the control to tie its caching
    conditions (in a way that is unclear to me) to those of child control whose
    ID matches the value of the VaryByControl attribute -- not quite what I'm
    looking for. (I suppose that, with some work, I might be able to kludge
    this into what I want, but...)

    I'm looking for a way to direct the control to cache itself separately for
    each value of an arbitrary specified property of that control. Sort of a
    VaryByProperty="Flag" which would cause the control to be cached separately
    for each value of the control's Flag property, as specified in the control's
    HTML declaration (i.e., separately for Flag="One", Flag="Two", etc.).

    I'm rather suprised that a VaryByProperty attribute of the @OutputCache
    directive does not already exist (whether by that name or some other).

    Again, unless I'm completely misunderstanding....

    - Tom Kiefer
    thogek @ earthlink . net


    "Eric Lawrence [MSFT]" <> wrote in message
    news:...
    > Just a guess-- Have you looked at VaryByControl?
    >
    >

    http://msdn.microsoft.com/library/d...pleversionsofusercontrolbasedonparameters.asp
    >
    > Thanks,
    >
    > Eric Lawrence
    > Program Manager
    > Assistance and Worldwide Services
    >
    > This posting is provided "AS IS" with no warranties, and confers no

    rights.
    >
    >
    > "Tom Kiefer" <> wrote in message
    > news:OML$...
    > > I'm guessing from the lack of response that there's no ready way to do

    > what
    > > I'm looking for. :-(
    > >
    > > If anyone from Microsoft is reading this, is there any indication that

    any
    > > future versions of ASP.NET might support what I attempt to describe

    below?
    > >
    > > - Tom Kiefer
    > > thogek @ earthlink . net
    > >
    > >
    > > "Tom Kiefer" <> wrote in message
    > > news:...
    > > > Question:
    > > > If I have an ASP.NET User Control which defines/exposes a property

    that
    > > the
    > > > page can use to specify a mode or data subset for the control to use,

    is
    > > > there a way to tell the @OutputCache directive to vary its cache based

    > on
    > > > that property value?
    > > >
    > > > I.e., I have:
    > > >
    > > > <my:control runat="server" id="mcOne" Flag="One" />
    > > > <my:control runat="server" id="mcTwo" Flag="Two" />
    > > >
    > > > where Flag is a public property of the code-behind class (whose value
    > > > affects the display output), and I want the Flag="One" instance to
    > > > output-cache separately from the Flag="Two" instance.
    > > >
    > > > So far, the control seems to output-cache only one version of the

    > control,
    > > > and all successive displays of the control use that cached version,
    > > > regardless of the Flag attribute value.
    > > >
    > > > Other notes:
    > > >
    > > > The @OutputCache directive's VaryByParam attribute works only with GET

    > and
    > > > POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
    > > >
    > > > Setting the @OutputCache directive's Shared attribute to "False"

    solves
    > > the
    > > > problem (by causing each usage of the control to cache separately),

    but
    > > has
    > > > the additional effect of requiring separate initial-loads and caches

    for
    > > > each page on which the control appears. Since I currently only have

    two
    > > or
    > > > three possible values of the Flag attribute, but these controls may

    > appear
    > > > on many pages (and there is some work invovled in the initial load of

    > the
    > > > data for this control), this is not ideal.
    > > >
    > > > There doesn't seem to be any sort of VaryByProperty attribute for
    > > > @OutputCache (which surprises me). So...
    > > >
    > > > Any other ideas?
    > > >
    > > > - Tom Kiefer
    > > > thogek @ earthlink . net
    > > >
    Tom Kiefer, Feb 9, 2004
    #6
  7. Tom Kiefer

    Corey O'Mara Guest

    I believe VaryByControl is what you're looking for. VayByControl should
    accept the name of a property of that control and you'll get different cache
    variations depending on the value set in the prop.

    --
    Corey O'Mara
    MCSD.NET, MCT

    "Tom Kiefer" <> wrote in message
    news:...
    > According to
    > http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconOutputCache.asp
    > and
    >

    http://msdn.microsoft.com/library/e...pleversionsofusercontrolbasedonparameters.asp,
    > this sounds like VaryByControl directs the control to tie its caching
    > conditions (in a way that is unclear to me) to those of child control

    whose
    > ID matches the value of the VaryByControl attribute -- not quite what I'm
    > looking for. (I suppose that, with some work, I might be able to kludge
    > this into what I want, but...)
    >
    > I'm looking for a way to direct the control to cache itself separately for
    > each value of an arbitrary specified property of that control. Sort of a
    > VaryByProperty="Flag" which would cause the control to be cached

    separately
    > for each value of the control's Flag property, as specified in the

    control's
    > HTML declaration (i.e., separately for Flag="One", Flag="Two", etc.).
    >
    > I'm rather suprised that a VaryByProperty attribute of the @OutputCache
    > directive does not already exist (whether by that name or some other).
    >
    > Again, unless I'm completely misunderstanding....
    >
    > - Tom Kiefer
    > thogek @ earthlink . net
    >
    >
    > "Eric Lawrence [MSFT]" <> wrote in message
    > news:...
    > > Just a guess-- Have you looked at VaryByControl?
    > >
    > >

    >

    http://msdn.microsoft.com/library/d...pleversionsofusercontrolbasedonparameters.asp
    > >
    > > Thanks,
    > >
    > > Eric Lawrence
    > > Program Manager
    > > Assistance and Worldwide Services
    > >
    > > This posting is provided "AS IS" with no warranties, and confers no

    > rights.
    > >
    > >
    > > "Tom Kiefer" <> wrote in message
    > > news:OML$...
    > > > I'm guessing from the lack of response that there's no ready way to do

    > > what
    > > > I'm looking for. :-(
    > > >
    > > > If anyone from Microsoft is reading this, is there any indication that

    > any
    > > > future versions of ASP.NET might support what I attempt to describe

    > below?
    > > >
    > > > - Tom Kiefer
    > > > thogek @ earthlink . net
    > > >
    > > >
    > > > "Tom Kiefer" <> wrote in message
    > > > news:...
    > > > > Question:
    > > > > If I have an ASP.NET User Control which defines/exposes a property

    > that
    > > > the
    > > > > page can use to specify a mode or data subset for the control to

    use,
    > is
    > > > > there a way to tell the @OutputCache directive to vary its cache

    based
    > > on
    > > > > that property value?
    > > > >
    > > > > I.e., I have:
    > > > >
    > > > > <my:control runat="server" id="mcOne" Flag="One" />
    > > > > <my:control runat="server" id="mcTwo" Flag="Two" />
    > > > >
    > > > > where Flag is a public property of the code-behind class (whose

    value
    > > > > affects the display output), and I want the Flag="One" instance to
    > > > > output-cache separately from the Flag="Two" instance.
    > > > >
    > > > > So far, the control seems to output-cache only one version of the

    > > control,
    > > > > and all successive displays of the control use that cached version,
    > > > > regardless of the Flag attribute value.
    > > > >
    > > > > Other notes:
    > > > >
    > > > > The @OutputCache directive's VaryByParam attribute works only with

    GET
    > > and
    > > > > POST values. (I did try VaryByParam="Flag" anyway, to no effect.)
    > > > >
    > > > > Setting the @OutputCache directive's Shared attribute to "False"

    > solves
    > > > the
    > > > > problem (by causing each usage of the control to cache separately),

    > but
    > > > has
    > > > > the additional effect of requiring separate initial-loads and caches

    > for
    > > > > each page on which the control appears. Since I currently only have

    > two
    > > > or
    > > > > three possible values of the Flag attribute, but these controls may

    > > appear
    > > > > on many pages (and there is some work invovled in the initial load

    of
    > > the
    > > > > data for this control), this is not ideal.
    > > > >
    > > > > There doesn't seem to be any sort of VaryByProperty attribute for
    > > > > @OutputCache (which surprises me). So...
    > > > >
    > > > > Any other ideas?
    > > > >
    > > > > - Tom Kiefer
    > > > > thogek @ earthlink . net
    > > > >

    >
    >
    Corey O'Mara, Feb 10, 2004
    #7
    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. =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=

    Problems with OutputCache declaration in User Control

    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=, Oct 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    536
    =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?=
    Oct 20, 2004
  2. Edward Wilde
    Replies:
    1
    Views:
    499
    Edward Wilde
    Dec 10, 2004
  3. alex
    Replies:
    2
    Views:
    2,194
    nosolicitado
    Jul 5, 2006
  4. Pete Griffiths
    Replies:
    0
    Views:
    3,100
    Pete Griffiths
    Feb 21, 2006
  5. Tom Kiefer
    Replies:
    6
    Views:
    227
    Corey O'Mara
    Feb 10, 2004
Loading...

Share This Page