.NETGURU
Localization and cache
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcache' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Ollie Cornes

Does custom output caching in ASP.NET allow me to cache on the basis of the
culture of the page? e.g. if I have URLs like article.aspx?id=123, I can
cache for each value of the id parameter, but can I also split the caching
to cover each copy of the page in the languages supported by article.aspx
(e.g. if article.aspx uses Thread.CurrentCulture to display different
content)?

Ollie
--
Click here to reveal e-mail address
.NET Books - http://www.cornes.org/books/

Reply to this message...
 
    
Brian Bilbro (VIP)
You'll want the varybyparam option:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht
ml/cpconoutputcache.asp

something like this should work:
<%@ OutputCache ..other options... VaryByParam="id" %>

HTHs,
Brian

----- Original Message -----
From: "Ollie Cornes" <Click here to reveal e-mail address>
Sent: Sunday, December 02, 2001 1:21 PM

> Does custom output caching in ASP.NET allow me to cache on the basis of
the
[Original message clipped]

Reply to this message...
 
    
G. Andrew Duthie (VIP)
I don't know if you can vary by the culture string easily, but it's
pretty straightforward to vary by the Accept-Language HTTP header, which
might work for you:

<%@ OutputCache Duration=3D"60" VaryByParam=3D"None"
VaryByHeader=3D"Accept-Language" %>

hth,

--
G. Andrew Duthie
Graymad Enterprises, Inc.
Click here to reveal e-mail address

[Original message clipped]

Reply to this message...
 
    
Brian Bilbro (VIP)
uh, yea..that probably works better. :)

--
Brian

----- Original Message -----
From: "G. Andrew Duthie" <Click here to reveal e-mail address>
To: "aspngcache" <Click here to reveal e-mail address>
Sent: Sunday, December 02, 2001 11:11 PM
Subject: [aspngcache] RE: Localization and cache

I don't know if you can vary by the culture string easily, but it's
pretty straightforward to vary by the Accept-Language HTTP header, which
might work for you:

<%@ OutputCache Duration="60" VaryByParam="None"
VaryByHeader="Accept-Language" %>

hth,

--
G. Andrew Duthie
Graymad Enterprises, Inc.
Click here to reveal e-mail address

[Original message clipped]

| [aspngcache] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngcache.asp = JOIN/QUIT

Reply to this message...
 
    
Ollie Cornes

Thanks Andrew, Brian.

The culture setting I need to vary by is the Thread.CurrentCulture value -
that value is set by a cookie that is configured by the user (through a UI),
it isn't available on the HTTP request parameter list and may not always be
the same as the Language header.

It looks like VaryByCustom is what I need with an override of
HttpApplication.GetVaryByCustomString in global.asax. I shall give that a
try and see how it goes - it's a shame the code has to go in global.asax,
I'd have preferred to keep it all within the page itself.

Ollie

----- Original Message -----
From: "Brian Bilbro" <Click here to reveal e-mail address>
To: "aspngcache" <Click here to reveal e-mail address>
Sent: Monday, December 03, 2001 4:21 AM
Subject: [aspngcache] RE: Localization and cache

[Original message clipped]

Reply to this message...
 
    
Ollie Cornes

The answer to this question is to use a line like this in the .aspx:

<%@ OutputCache Duration="600" varybyparam="id"
varybycustom="LanguageChoice" %>

Then I set up the LanguageChoice custom caching value in my global.asax.cs
like this:

public override string GetVaryByCustomString(HttpContext context, string
arg)
{
switch (arg)
{
case "LanguageChoice":
string langChoice = "";
if (Request.Cookies["CulturePref"] != null)
{
langChoice = Request.Cookies["CulturePref"].Value;
}
return "LanguageChoice=" + langChoice;
default:
return "";
}
}

In my case the cookie (CulturePref) stores the user's culture (e.g. en-GB),
so I cache on the basis of that value.

Works like a charm.

Ollie
--
Click here to reveal e-mail address
.NET Books - http://www.cornes.org/books/

----- Original Message -----
From: "Brian Bilbro" <Click here to reveal e-mail address>
To: "aspngcache" <Click here to reveal e-mail address>
Sent: Monday, December 03, 2001 4:21 AM
Subject: [aspngcache] RE: Localization and cache

[Original message clipped]

Reply to this message...
 
 
System.Threading.Thread
System.Web.HttpApplication
System.Web.HttpContext




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification