0

I have a multi lingual joomla site that uses Joomfish for translations. Due to Joomfish using a cookie to change language and not a different url I have had major issues getting this to work. However I have found a way to get round it by getting varnish to check the cookie value, if english serve cache, if anything else then pass to server.

Thats great, but I want to be able to cache the other versions. Is there a way to serve a different cache to different languages. So a cached version of german, french etc.

I have tried using different nginx config files and setting different varnish back ends but that didnt seem to work.

For that I did:

/* default is english */
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

/* french backend */
backend french {
    .host = "127.0.0.1";
    .port = "8081";
}

Then in my sub recv function:

if(req.http.cookie ~ "jfcookie\[lang\]=fr"){
    set req.backend = french;
}

That seems to serve the same cached backend though. So if your on french it sends you to english content.

DavidT
  • 2,341
  • 22
  • 30

2 Answers2

1

I believe you can simply handle this by sending a vary header, You could let your app set a header for example X-language and send a header Vary: X-language this way varnish would understand that there's 2 different languages and cache each separately.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • Thanks, is this a solid solution? I have read there could be two ways, your way and the hashing way as described here: http://stackoverflow.com/questions/19058660/varnish-how-to-separately-cache-pages-based-on-value-of-a-specific-cookie That explains about Drupal, mine is Joomla I am assuming the sanitising bit will therefore be different for me. – DavidT Feb 13 '14 at 12:18
  • Both are valid solutions with different approaches, but you're right cookie for Joomla and Drupal are different... so you should choose between adapting your app to produce a custom header or go for a pure Varnish solution. – NITEMAN Feb 15 '14 at 10:21
0

I have this working now. For anyone in the same situation, check out hashing. I have detailed below my solution.

sub vcl_recv {
    if(req.http.cookie ~ "jfcookie\[lang\]=fr"){
        set req.http.X-Cookie-Language = "fr";
    }
}

sub vcl_hash {
    hash_data(req.http.X-Cookie-Language);
}
DavidT
  • 2,341
  • 22
  • 30