473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Programmatic use of SetVaryByCustom

DV
Has anyone experienced any problems with the use of
Response.Cache.SetVaryByCustom within their code?

I have page which is set to cache the contents for a
certain time (time varies depending on url)

Response.Cache.SetCacheability(HttpCacheability.Se rver);
Response.Cache.SetExpires((DateTime.Now.AddSeconds
(obj.CacheTimeout)));
Response.Cache.VaryByParams["*"] = true;

And I cache per user via
Response.Cache.SetVaryByCustom("authuser");

This works fine.

BUT if I programmatically decide whether to use the custom
auth or not the cache is cleared for all cached versions
of the page (regardless of the url arguments).
e.g.

if(obj.Confidential)
Response.Cache.SetVaryByCustom("authuser");

e.g. The page I am caching generates a chart and these
charts can be included several times within a page. If
some charts use SetVaryByCustom and some don't then no
caching occurs. If all charts use SetVaryByCustom then all
charts are cached per user.

many thanks,

Darren



Nov 18 '05 #1
10 3646
DV
Forget to mention that, yes, I have implemented
GetVaryByCustomString within global.aspx
-----Original Message-----
Has anyone experienced any problems with the use of
Response.Cache.SetVaryByCustom within their code?

I have page which is set to cache the contents for a
certain time (time varies depending on url)

Response.Cache.SetCacheability(HttpCacheability.Se rver);
Response.Cache.SetExpires((DateTime.Now.AddSeconds
(obj.CacheTimeout)));
Response.Cache.VaryByParams["*"] = true;

And I cache per user via
Response.Cache.SetVaryByCustom("authuser");

This works fine.

BUT if I programmatically decide whether to use the customauth or not the cache is cleared for all cached versions
of the page (regardless of the url arguments).
e.g.

if(obj.Confidential)
Response.Cache.SetVaryByCustom("authuser");

e.g. The page I am caching generates a chart and these
charts can be included several times within a page. If
some charts use SetVaryByCustom and some don't then no
caching occurs. If all charts use SetVaryByCustom then allcharts are cached per user.

many thanks,

Darren



.

Nov 18 '05 #2
I don't know if this will help have your tried adding
Response.Cache.SetValidUntilExpires(True)

"DV" <12*@123.com> wrote in message
news:08****************************@phx.gbl...
Forget to mention that, yes, I have implemented
GetVaryByCustomString within global.aspx
-----Original Message-----
Has anyone experienced any problems with the use of
Response.Cache.SetVaryByCustom within their code?

I have page which is set to cache the contents for a
certain time (time varies depending on url)

Response.Cache.SetCacheability(HttpCacheability.Se rver);
Response.Cache.SetExpires((DateTime.Now.AddSeconds
(obj.CacheTimeout)));
Response.Cache.VaryByParams["*"] = true;

And I cache per user via
Response.Cache.SetVaryByCustom("authuser");

This works fine.

BUT if I programmatically decide whether to use the

custom
auth or not the cache is cleared for all cached versions
of the page (regardless of the url arguments).
e.g.

if(obj.Confidential)
Response.Cache.SetVaryByCustom("authuser");

e.g. The page I am caching generates a chart and these
charts can be included several times within a page. If
some charts use SetVaryByCustom and some don't then no
caching occurs. If all charts use SetVaryByCustom then

all
charts are cached per user.

many thanks,

Darren



.

Nov 18 '05 #3
DV
Thanks for the tip - sadly it didn't fix the problem.

It's weird how the framework can cache the page based on
the url and have different expiry times for each one but
not support have varybycustom set for some but not all.

D
-----Original Message-----
I don't know if this will help have your tried adding
Response.Cache.SetValidUntilExpires(True)

"DV" <12*@123.com> wrote in message
news:08****************************@phx.gbl...
Forget to mention that, yes, I have implemented
GetVaryByCustomString within global.aspx
>-----Original Message-----
>Has anyone experienced any problems with the use of
>Response.Cache.SetVaryByCustom within their code?
>
>I have page which is set to cache the contents for a
>certain time (time varies depending on url)
>
> Response.Cache.SetCacheability (HttpCacheability.Server); > Response.Cache.SetExpires((DateTime.Now.AddSeconds
>(obj.CacheTimeout)));
> Response.Cache.VaryByParams["*"] = true;
>
>And I cache per user via
>Response.Cache.SetVaryByCustom("authuser");
>
>This works fine.
>
>BUT if I programmatically decide whether to use the

custom
>auth or not the cache is cleared for all cached versions >of the page (regardless of the url arguments).
>e.g.
>
>if(obj.Confidential)
> Response.Cache.SetVaryByCustom("authuser");
>
>e.g. The page I am caching generates a chart and these
>charts can be included several times within a page. If
>some charts use SetVaryByCustom and some don't then no
>caching occurs. If all charts use SetVaryByCustom then

all
>charts are cached per user.
>
>many thanks,
>
>Darren


Nov 18 '05 #4
Hi DV,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and am researching on it now. I will update
you as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #5
Hi DV,

Based on my research, it seems to be an issue by design. Only when all
parts on a web page applied the SetVaryByCustom, does the cache works.
However, I need to do a further confirmation, and I will post back here.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #6
DV
Thanks for the time taken already - it would seem you
concur.

The server cache supports different expiry times for the
different url arguments (same aspx) but it is a pity it
doesn't apply the SetVaryByCustom in a similar manner. It
seems the SetVaryByCustom can only be applied to the aspx
(regardless of url). If this is intentional then it may be
worth commenting on this within the documentation?

I look forward to any updates you may have...

Darren
-----Original Message-----
Hi DV,

Based on my research, it seems to be an issue by design. Only when all parts on a web page applied the SetVaryByCustom, does the cache works. However, I need to do a further confirmation, and I will post back here.
Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 18 '05 #7
Hello,

After studied the problem, I think the problem may not be related to the
expire time. As Jacob mention, we can only have one cache policy for a
single cached component. Since all of your charts are in same web form, I
think they should use same cache policy. If my understanding is inccorect,
please feel free to correct me.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8
dv

The aspx page chart.aspx returns the requested chart by
dynamically drawing the chart and includes the date
generated and the authenticated username that requested it
within the graphic.

The code of chart.aspx includes the following lines of
code:

Response.Cache.SetCacheability(HttpCacheability.Se rver);
Response.Cache.SetExpires((DateTime.Now.AddSeconds (
chartid * 30 )));
Response.Cache.VaryByParams["*"] = true;
Response.Cache.SetValidUntilExpires(true);

#TEST A#
By loading display.htm as UserA in the browser and
repeatedly hitting refresh you can see that the generated
charts are cached and each chart gets refreshed using it
own assigned expiry time - as you'd expect. If you go to
another users machine (UserB) and do the same you'll
initially see cached charts which were generated for UserA
(and not UserB) - again as you'd expect.

Now add the line:
Response.Cache.SetVaryByCustom("authuser");

and implement the function below within global.aspx

public override string GetVaryByCustomString(HttpContext
context, string arg)
{
if (arg.ToLower() == "authuser" &&
context.User.Identity.IsAuthenticated)
{
return context.User.Identity.Name;
}
}

#TEST B#
Now by loading display.htm and repeating TEST A you will
find that each user has their own individual cached copy
of the chart. Again each chart will have it's own expiry
time. No surprises there.

But if we were to programmatically decide whether the
chart should be cached per user by adding

if(chartid % 2 == 0)
Response.Cache.SetVaryByCustom("authuser");

and then repeating 'TEST A' you'd expect some charts to be
shared between users and some not - what actually happens
is the cache (for all copies of chart.aspx -regardless of
url) are cleared when SetVaryByCustom is switch on and off
between generated charts effectively turning off caching.

I hope this explains the problem. It's not a show stopper
for me but I think it is an issue that should either be
documented or fixed.

Many thanks for taking an interest

Darren Voisey

[my hotmail address is obvious]
-----Original Message-----
Hello,

After studied the problem, I think the problem may not be related to theexpire time. As Jacob mention, we can only have one cache policy for asingle cached component. Since all of your charts are in same web form, Ithink they should use same cache policy. If my understanding is inccorect,please feel free to correct me.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers norights.)

.

Nov 18 '05 #9
DV
...the start of previous post my seems to have been cut
out...

display.htm contains HTML that contains 4 IMG tags with
their SRC attribute set to load from chart.apsx.

e.g

Image 1 would load from = chart.aspx?chartid=1
Image 2 would load from = chart.aspx?chartid=2
Image 3 would load from = chart.aspx?chartid=3
Image 4 would load from = chart.aspx?chartid=4
-----Original Message-----

The aspx page chart.aspx returns the requested chart by
dynamically drawing the chart and includes the date
generated and the authenticated username that requested itwithin the graphic.

The code of chart.aspx includes the following lines of
code:

Response.Cache.SetCacheability(HttpCacheability.S erver);
Response.Cache.SetExpires((DateTime.Now.AddSecond s(
chartid * 30 )));
Response.Cache.VaryByParams["*"] = true;
Response.Cache.SetValidUntilExpires(true);

#TEST A#
By loading display.htm as UserA in the browser and
repeatedly hitting refresh you can see that the generated
charts are cached and each chart gets refreshed using it
own assigned expiry time - as you'd expect. If you go to
another users machine (UserB) and do the same you'll
initially see cached charts which were generated for UserA(and not UserB) - again as you'd expect.

Now add the line:
Response.Cache.SetVaryByCustom("authuser");

and implement the function below within global.aspx

public override string GetVaryByCustomString(HttpContext
context, string arg)
{
if (arg.ToLower() == "authuser" &&
context.User.Identity.IsAuthenticated)
{
return context.User.Identity.Name;
}
}

#TEST B#
Now by loading display.htm and repeating TEST A you will
find that each user has their own individual cached copy
of the chart. Again each chart will have it's own expiry
time. No surprises there.

But if we were to programmatically decide whether the
chart should be cached per user by adding

if(chartid % 2 == 0)
Response.Cache.SetVaryByCustom("authuser");

and then repeating 'TEST A' you'd expect some charts to beshared between users and some not - what actually happens
is the cache (for all copies of chart.aspx -regardless of
url) are cleared when SetVaryByCustom is switch on and offbetween generated charts effectively turning off caching.

I hope this explains the problem. It's not a show stopper
for me but I think it is an issue that should either be
documented or fixed.

Many thanks for taking an interest

Darren Voisey

[my hotmail address is obvious]
-----Original Message-----
Hello,

After studied the problem, I think the problem may not
berelated to the
expire time. As Jacob mention, we can only have one
cachepolicy for a
single cached component. Since all of your charts are in

same web form, I
think they should use same cache policy. If my

understanding is inccorect,
please feel free to correct me.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties,

and confers no
rights.)

.

.

Nov 18 '05 #10
hi Darren,

I think the key point is following:

"you'd expect some charts to be shared between users and some not"

With SetVaryByCustom and a same aspx form, the ASP.NET cache will only
apply the custom policy to a same aspx, it can't allow a copy without a
"user id" as index.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave Boyd | last post by:
Are there arguments for the built-in commands called via RunCommand such as acCmdNewObjectReport or do they always require interactive input? Is the code behind the built-in commands exposed...
3
by: MikeM | last post by:
I've been trying to locate some property or method that will allow programmatic access to the "loginUrl" attribute in the web.config file in the <system.web> -> <authentication> element when the...
0
by: Daniel | last post by:
programmatic to ftp virtual directories when i connect to an ftp server and i only have access to a few of the ftp virtual directories, do i just change directory to them after connecting and...
6
by: Blaine Manyluk | last post by:
I have a very unusual request. I need to be able to generate reports and save them as TIF files, with full programmatic control. The application will provide the filenames. Each page of the...
2
by: williamphenryjr | last post by:
This is a long post. If you have answers I'm ready. If you have web links, that'd be great too. I'm a Junior/Senior in Computer Science at Washington State University, so you can make some...
2
by: myzm | last post by:
I want to provide a menu for user to log out system after they logged in using the Login control. Nowhere I can find information about programmatic logout. Any help? Thanks.
2
by: matt.delvecchio | last post by:
hello, i have a user control that works great, when its used as a design-time controls. however, when i try to use it as a programmtic control, im running into troubles. the control is pretty...
0
by: tvaughan77 | last post by:
True or false: In Windows 2000, the user account that runs IIS (typically ASPNET) *must* be allowed to "Act as part of the operating system" in order for impersonation to work? Is that also...
9
by: Axxe | last post by:
I have searched high and low for cogent, well-explained coding to complete a project on which I have spent six months of work. I stumbled across something on this site that is close to what I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.