How to force a reload of cached user control?

E

Edward Chung

I create a user control that is used as a page header for all
application's pages. The user control contains a HyperLink control named
accountHyperlink whose text can either set to "Account/Logon" or
"Account/Logout" depending on whether the user is logged on. I want to cache
this user control for 1 hour but have it automatically reloaded if the
accountHyperlink.Text is changed. So I place the following line of code on
its ascx page:

<% @OutputCache%@ OutputCache Duration="3600" VaryByParam="none"
VaryByControl="accountHyperlink" %>

The user control is not refreshed on other pages that use it after the
accountHyperlink.Text changed. So do I use incorrect codes for my purpose or
do I need to place more codes (somewhere) to force the user control to
reload to reflect the change?
 
S

Steve Lutz

Edward,
Is it possible to just have the item change it's text based on the logged in
status of the user? By using a cache, you are leaving a lot of work to
unknown possibilities. The cache could be overwritten because it ran out of
space and needed the cache room for something else. Also, the cache could be
reset elsewhere, either in code, or by an application restart. Generally, I
only use the cache for storing items that I can 1) always recreate and 2) do
not care about the state of the cached entry.
If you cannot recreate the control, then what happens when the cache
expires? It COULD expire before the 3600 minutes remember.

HTH

Steve
 
A

Aquila Deus

Edward said:
I create a user control that is used as a page header for all
application's pages. The user control contains a HyperLink control named
accountHyperlink whose text can either set to "Account/Logon" or
"Account/Logout" depending on whether the user is logged on. I want to cache
this user control for 1 hour but have it automatically reloaded if the
accountHyperlink.Text is changed. So I place the following line of code on
its ascx page:

<% @OutputCache%@ OutputCache Duration="3600" VaryByParam="none"
VaryByControl="accountHyperlink" %>

The user control is not refreshed on other pages that use it after the
accountHyperlink.Text changed. So do I use incorrect codes for my purpose or
do I need to place more codes (somewhere) to force the user control to
reload to reflect the change?

http://www.dotnet247.com/247reference/msgs/11/59941.aspx
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top