Groups | Blog | Home
all groups > asp.net caching > february 2004 >

asp.net caching : Caching only for anonymous user


Stefan [MSFT]
2/24/2004 9:47:00 AM
Hi Gabriele,

you could add some logic to the template to check if currently an
authenticated users is logged in and display different content.
Or create a parallel channel and redirect to this when the user is
authenticated.

Cheers,
Stefan.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]

Stefan [MSFT]
2/24/2004 10:27:50 AM
Hi Gabriele,

you could do a different approach:
implement a new varyon... and check if the current user is authenticated.
If yes, then create a new random key. this will ensure that a new instance
is served.
For guests always render the same key.

How to implement this is here:
http://weblogs.asp.net/stefan_gossner/archive/2003/12/23/45417.aspx

Please be aware that this will cause lots of copies to be stored in output
cache so it might not scale very well....

Cheers,
Stefan.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]

Gabriele Cannata
2/24/2004 6:28:57 PM
Sorry if this is a FAQ,
we have a site that is mainly visited by anonymous users, and we have some
complex pages (they are really CMS templates, by the way).
We are thinking about the possibility of caching only the "guest" version of
a page, while processing the page for each authenticated users. Is it
possible?

Gabriele

Gabriele Cannata
2/24/2004 7:08:41 PM
Hi Stefan, actually to execute some logic, you must actually process the
page. What we had in mind was to enable OutputCache on all pages, and then
add a HttpModule to check for some kind of authentication (eg. a cookie) and
in the case the user is authenticate, disable caching forcing asp.net to
process the page, while for anonymous letting the default behaviour of
OutputCacheModule to serve the request from the Cache.
What we weren't able to do was to force the OutputCacheModule to not serve
the request from the cache just for some pages.

I'm thinkingabout implementing a
"OnPreRequestHandlerExecute"/"OnPostRequestHandlerExecute" to avoid caching
of request coming from authenticated user, but it's not clear to me the
right way to go.

For CMS guys:

In CMS, curiously, to disable caching of controls in authoring mode, you can
use "VaryByCustom=CmsControl" which actually
causes GetvaryByCustomString to give a continuosly incrementing integer, so
that for every request you get a new cache entry.
This could be a way to forcing the execution of a page, but the memory waste
would be worse than caching for each user visiting the site.

Any comment?

"Stefan [MSFT]" <stefang@online.microsoft.com> ha scritto nel messaggio
news:%23ta$24v%23DHA.3500@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Gabriele Cannata
2/24/2004 7:38:16 PM
Thanks Stefan,
that is actually what I meant, and that's why I was looking for a better
solution. Still, I wonder why CMS guys chose that approach for User
Controls, I guess that with many authors online and a long cache duration it
would be a big waste of memory, even worse if the authoring machine is also
a production machine.

"Stefan [MSFT]" <stefang@online.microsoft.com> ha scritto nel messaggio
news:OL9EqPw%23DHA.792@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Anamika
4/8/2004 9:46:05 PM
Hello Stefan

I am a novice in the field of caching and wanted some insight in this field. I am looking for the best possible way of caching content which takes care of authentication.Meaning, I have the same content to deliver, but authentication enables some extra content to appear. What is the standard way to handle such a scenario

AddThis Social Bookmark Button