0

I know it's very basic question but still I am confuse about it's implements. In one of my interview, they asked me that I have a website which is multilingual (10 languages). I want to put all the contents in a cache. May I know how to achieve this functionality? Is it anything specific we need to write in Output cache?

My all contents are resides in resource files.

alok_dida
  • 1,723
  • 2
  • 17
  • 36

2 Answers2

3

I am assuming that you are asking it in the context of output caching, so a simple approach is to use VaryByCustom. For example,

<%@ OutputCache VaryByCustom="Culture" ... %>

And in global.asax

public override string GetVaryByCustomString(HttpContext Context, string Custom)
{
    if (Custom == "Culture")
    {
        // return culture specific string
        return Context.Request.UserLanguages[0];  
    }
    return base.GetVaryByCustomString(Context, Custom);
}

The implementation will vary depending upon how you are tracking the current user's culture. For example, you might be using session variable (or profile data), so you need to return the current user's culture based on session variable etc.

From SEO friendly-ness (can matter if your web site is content oriented), you may want to have culture info as part of your url. For example,

<%@ OutputCache ... varybyparam="Culture" %>

http://www.yourdomain.com/somepage.aspx?Culture=en

http://www.yourdomain.com/somepage.aspx?Culture=fr
VinayC
  • 47,395
  • 5
  • 59
  • 72
  • It is in a session variable. If I am appending a Culture in a URL then based on url it will fetch the information from the cache, so for this I dont have to write anything in output cache but what about when it stores in a Session variable. – alok_dida Dec 28 '12 at 09:03
  • @alok_dida, read the answer carefully! Culture in url is one of the approach. You can always use `VaryByCustom` - instead of `Context.Request.UserLanguages[0]` you may have to return it from session - something like `Context.Session["Culture"]` – VinayC Dec 28 '12 at 09:06
1

No, except obviously you should ahve different URL's per language - but that is needed anyawy otherwise only the Default langauge will EVER be in search engines (which do not remember Cookies etc.).

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • URL will be same. It's not different. Is it possible to achieve? – alok_dida Dec 28 '12 at 08:49
  • 1
    No. Basically that is a no go. Caching will work by URL alone, and anyone doing multi langauge under the same URL is "SEO Challenged" and should not design websites. You NEED to have the culture / language as part of the URL, otherwise search engines only see one language, ever, as they use the URL to distinguish items. Someone needs "how the web works for beginners" to design a proper URL space. – TomTom Dec 28 '12 at 09:01
  • +1 for answer to "how to cache if SEO is important". Also it will not answer the interview question - one is likely expected to ask questions (i.e. if SEO is important, if content delivered directly or via CDN...) - and knowing another answer (+1 to @VinayC) is useful for interview... – Alexei Levenkov Dec 28 '12 at 09:30