Flush pages cache

How do I flush the pages cache in Kirby 3? It is enabled in the config.php:

'pages' => [
  'active' => true,
  'ignore' => ["contact", "search"]

I’ld need it in a route.

I’ve tried $kirby->cache('pages')->flush(), but that isn’t doing much?


That should work, provided you have defined $kirby before, otherwise use kirby()->cache('pages')->flush()

I’m not getting errors, but the cache ain’t flushed either :thinking:.

Hm, got to test this. In a template, the above code works as expected.

I am not sure if its wrong to “hijack” this thread but I was about to ask a similar question. Is it possible flush the cache (the cache folder inside “site”) on deployment for example? Any scripts or command line tools?


@bvdputte Could you please post your code, flushing the cache works for me, although the route itself returns an error in my quick and dirty test.

@Philip If you flush the pages cache, only the pages cache folders are cleared. But you can, of course, also flush the other caches, including via script.

However, depending on how you deploy, this might not be necessary, because if you deploy via git or rsync, you could exclude the files for your deployment process.

@texnixe Thanks for quick reply. I get your point about the gitignore however my concern is that if I change something in the template locally and push to git and then deploy to server how would I go about making sure the cache is flushed/cleared?

I assume html markup is cached despite the cache is not creating a 100% static html file per page.

@Philip Well, if you deploy manually like pushing your files over via SFTP, then you have to also manually clear the cache folder.

If you deploy with git, you can use a git hook to clear the folder.

With an rsync workflow, you could make it part of your script (@jimbobrjames is our rsync expert)

1 Like

Nevermind @texnixe, I made an error :see_no_evil:. The code works as expected, obviously.