Question

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.

Was it helpful?

Solution 2

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);
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top