getkirby.com icon indicating copy to clipboard operation
getkirby.com copied to clipboard

Docs: How to set up cache for multilingual site with different URLs

Open zanstro opened this issue 4 years ago • 7 comments

Describe the bug
I have a Kirby multilingual site and I use different URLs for each language. When I update a page in English the cache is cleared but this doesn’t happen when I update a page in a different language. Actually, when I update a page in a different language the system clears the cache of the English cache pages directory. I currently use two languages EN as default and IT.

The structure of the cache folders in my case is as follows:

site/cache/www.example.co.uk/pages/ url-key.en.html.cache

and

site/cache/www.example.it/pages/ url-key.it.html.cache

The language setup for en is this:

return [
    'code' => 'en',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'en_GB'
    ],
    'name' => 'English',
    'translations' => Yaml::decode(F::read(kirby()->root('languages').'/vars/en.yml')),
    'url' => 'https://www.example.co.uk',
];

Accordingly for it lang the setup is this:

return [
    'code' => 'it',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'it_IT'
    ],
    'name' => 'Italian',
    'translations' => Yaml::decode(F::read(kirby()->root('languages').'/vars/it.yml')),
    'url' => 'https://www.example.it'
];

The cache setup config is as follows:

return [
    'cache' => [
    'pages' => [
        'active' => true,
        'ignore' => function ($page) {
            return in_array($page->slug(), ['contact', 'blog']);
        }
    ]
]
];

Kirby Version
3.4.3

zanstro avatar Oct 01 '20 06:10 zanstro

I think this is related to getkirby/kirby#2248

medienbaecker avatar Oct 01 '20 07:10 medienbaecker

Thank you @medienbaecker that's correct. The difference though is that the proposed solution cannot be applied to my case. It's ok to use a canonical URL for www.example.com and example.com but this is not acceptable when you have two different TLDs (.co.uk and .it in my case).

Is there any different solution that can be applied to my case? I see that using the cache prefix would mean that page-level caches will be mixed. So if I understand correctly if the first users to a /foo page visits as www.example.co.uk/foo, and that page is cached, then another user that visits www.example.it/foo will receive a page that links to www.example.co.uk pages.

zanstro avatar Oct 01 '20 07:10 zanstro

Hello from me too. I have the same problem. I am working with 3 languages at the moment (en, gr, rs)

returnmk avatar Oct 02 '20 08:10 returnmk

@returnmk You can set a prefix as a workaround.

return [
    'debug' => true,
    'languages' => true,
    'cache' => [
      'pages' => [
        'active' => true,
        'prefix' => 'kirby'
      ]
    ]
];

afbora avatar Jan 27 '21 20:01 afbora

@bastianallgeier do you still think this is a bug? Based on the discussion in https://github.com/getkirby/kirby/issues/2248, I would think @afbora's comment is the solution for this use case.

distantnative avatar Jul 19 '21 16:07 distantnative

I think it is. Since the $page->cacheId() also contains the language code, the cache entries shouldn't be shared even if the page URIs on these domains are the same – the entries will still differ by language code.

lukasbestle avatar Jul 19 '21 19:07 lukasbestle

I feel like we should document this more clearly and then close these two issues.

lukasbestle avatar Jul 19 '21 19:07 lukasbestle

I just ran into this issues again ☹️

I looked for a fix here: https://getkirby.com/docs/guide/languages/introduction#language-specific-urls Before I googled it and found my own issue from April 🙈

mrflix avatar Dec 05 '22 10:12 mrflix

Sorry for the huge delay. I've finally resolved this and used the opportunity to improve other parts of the caching docs as well.

lukasbestle avatar Dec 27 '22 13:12 lukasbestle