[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

OutputCache directive vs Response.Cache.SetCacheability

idonix

2/23/2006 10:58:00 AM

Hi folks,

I have an infuriating problem. I have a number of pages that I want to cache
server-side only, using varybycustom. It is a requirement that we set
different expiry times for different instances of the page - based on the
varybycustom params.

I have implemented a GetVaryByCustomString in my global.asax. I am setting
the caching behaviour in the Page_Load as follows:

Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
Response.Cache.SetValidUntilExpires(True)
Response.Cache.SetVaryByCustom("report.aspx")
Response.Cache.SetExpires(<calculated time based on varybycustom>)

My problem is that this works most of the time, but occasionally the caching
just
stops working - the page is rendered on every request (and the
Global.GetVaryByCustomString stops getting called). The only way to fix this
is to add an OutputCache directive to the page, at which point the caching
works reliably. The problem here though is that the Duration attribute
(which is required) of the directive overrides the value I'm setting in
Response.Cache.SetExpires.

Any thoughts?

(this is asp.net 1.1)

Pete Griffiths


5 Answers

v-yren

2/24/2006 7:13:00 AM

0

Hi Pete,

Thanks for posting!

For the current issue, the problem is that cache doesn't work sometimes in
the current ASP.NET application. If I have misunderstood anything, please
let me know.

As far as I know, using the "OutputCache" is same as setting these things
programmatically. Then, I think the current resolution isn't appropriate.
This means maybe the problem still occurs sometimes.

I wonder when the problem is encountered, whether the usage of memory is
high or something else. Could you please give me some more details about
the environment?

By the way, I suggest you can move the code from the Page_Load event to the
Application_BeginRequest event in the Global.asax file. Something likes
below:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Context.Response.Cache.SetCacheability( HttpCacheability.Server);
Context.Response.Cache.VaryByParams.IgnoreParams = true;
Context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(count));
...
}

Thanks for your understanding. I'm looking forward your reply!

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================

idonix

3/3/2006 10:21:00 AM

0

Hi Yuan,

I have moved the code to BeginRequest, as you suggest, but unfortunately
this makes no difference. ASP.NET doesn't reliably call GetVaryByCustomString
unless I add the OutputCache directive to the aspx files.

It's a development environment - XP Pro SP2, with 1GB RAM.

Pete


""Yuan Ren[MSFT]"" wrote:

> Hi Pete,
>
> Thanks for posting!
>
> For the current issue, the problem is that cache doesn't work sometimes in
> the current ASP.NET application. If I have misunderstood anything, please
> let me know.
>
> As far as I know, using the "OutputCache" is same as setting these things
> programmatically. Then, I think the current resolution isn't appropriate.
> This means maybe the problem still occurs sometimes.
>
> I wonder when the problem is encountered, whether the usage of memory is
> high or something else. Could you please give me some more details about
> the environment?
>
> By the way, I suggest you can move the code from the Page_Load event to the
> Application_BeginRequest event in the Global.asax file. Something likes
> below:
> protected void Application_BeginRequest(Object sender, EventArgs e)
> {
> Context.Response.Cache.SetCacheability( HttpCacheability.Server);
> Context.Response.Cache.VaryByParams.IgnoreParams = true;
> Context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(count));
> ...
> }
>
> Thanks for your understanding. I'm looking forward your reply!
>
> Yuan Ren [MSFT]
> Microsoft Online Support
> ======================================================
> PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
> updated on February 14, 2006. Please complete a re-registration process
> by entering the secure code mmpng06 when prompted. Once you have
> entered the secure code mmpng06, you will be able to update your profile
> and access the partner newsgroups.
> ======================================================
> When responding to posts, please "Reply to Group" via your newsreader
> so that others may learn and benefit from this issue.
> ======================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> ======================================================
>
>

v-yren

3/7/2006 11:09:00 AM

0

Hi Pete,

Really sorry for some confusion! I think I am so careless9

I don't mean ignore the customize string. Please change the following
context:
"Context.Response.Cache.VaryByParams.IgnoreParams = true;"
to
"Context.Response.Cache.SetVaryByCustom("report.aspx")"

Please tell me about the result. I'm sorry for this confusion. Hope you
will understand me.

Thanks.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================

idonix

3/7/2006 4:32:00 PM

0

Sorry Yuan...

We are already using SetVaryByCustom, and this <usually> works perfectly.
However sometimes it will just stop working (ie GetVaryByCustomString is no
longer called). The only way to fix this is to add the page directive - but
this stops us setting the duration in code.

Pete

""Yuan Ren[MSFT]"" <v-yren@online.microsoft.com> wrote in message
news:dyamLedQGHA.8156@TK2MSFTNGXA03.phx.gbl...
> Hi Pete,
>
> Really sorry for some confusion! I think I am so careless9
>
> I don't mean ignore the customize string. Please change the following
> context:
> "Context.Response.Cache.VaryByParams.IgnoreParams = true;"
> to
> "Context.Response.Cache.SetVaryByCustom("report.aspx")"
>
> Please tell me about the result. I'm sorry for this confusion. Hope you
> will understand me.
>
> Thanks.
>
> Regards,
>
> Yuan Ren [MSFT]
> Microsoft Online Support
> ======================================================
> PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
> updated on February 14, 2006. Please complete a re-registration process
> by entering the secure code mmpng06 when prompted. Once you have
> entered the secure code mmpng06, you will be able to update your profile
> and access the partner newsgroups.
> ======================================================
> When responding to posts, please "Reply to Group" via your newsreader
> so that others may learn and benefit from this issue.
> ======================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ======================================================
>


v-yren

3/9/2006 3:30:00 AM

0

Hi Pete,

Sorry for confusion!

Based on my experience, there is no difference between coding the cache in
application and adding the page directive. I think the current issue is
that the cache doesn't work sometimes. However, from your description, it
seems the cache always works well under the page directive is added. The
only different is the setting of duration. I think maybe the duration masks
the real root cause for the current issue.

I want to know when the cache lost whether the memory is released for the
current process. This means I wonder when the issue occurs whether the
usage of memory is high. Could please give me more details about this?

BTW, I also want to know if the cache lost, does it work fine later. Or you
have to recycle the process manually to make the cache work again.

Thanks for your understanding. I'm looking forward your reply!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support