Clear cache on page update

I have Kirby cache enabled and I change the content of a page through the panel but after the update, still, the cached version of the page is loaded.

I thought then to add this kirby()->cache('pages')->flush() to the page.update:after hook I have inside config.php. I have the latest version of Kirby (3.4.3) and I used this code $this->cache('pages')->flush();

Am I doing something wrong? I used just $this following this reference: https://getkirby.com/docs/reference/plugins/extensions/hooks#accessing-kirby-site-and-user-in-a-hook-callback

Thank you in advance for your help.

Hi Zanstro and welcome to the Kirby Forums.

Cache should be cleared automatically for you when you update a page using the panel. No hooks or other extra code required. You can check if cache gets flushed if you look in the /site/cache-directory on the webserver.

Thank you for your quick reply!

Yes, I check the particular directory and nothing changes when I update a page all the files remain the same.

The only things that come to my mind and could probably cause a problem are that the site is multilingual and that I have installed Kirby through composer so maybe there is a permissions issue.

It’s actually the multilingual. 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.

I don’t know if this is related to the fact that I use different URLs for each language.

Actually, when I update a page in a different language the system clears the cache of the English cache pages directory.

Below the cache directory, there are subdirectories with the domain for each language as a name.

So weird. In my experience I have a site/cache directory, where there’s a pages subdirectory. Cached versions for each available page are saved like this: url-key.{language-code}.html.cache (e.g. home.fr.html.cache).

Upon each modification in the panel the pages-directory is cleared. And it gets regenerated as soon as there are active users on the website.

Just to be clear; in your case the *.{other then default language}.html.cache files persist in site/cache/pages/ upon changes via the panel?

Can you maybe share your languages and cache setup config?

The structure 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']);
        }
    ]
]
];

Thanks for that. I never used this kind of setup. I’ld try to replicate it in the starterkit and if it doesn’t work as expected there neither, I’ld file a bug report on github.

Hello bvdputte, did you have the time to test it locally with the starterkit?

Hi @zanstro, I think we’ve got lost in translation somewhere :slight_smile:

I’m not gonna test it, I proposed if it was my problem I’ld try to replicate it. That’s where I tried to ask you to replicate it in a fresh starterkit as you know what the problem is and if it’s solved with it.

:v: