Bypass pages cache conditionally during bootstrap

I like to have Kirby’s pages cache on in most of my projects (not staticache!).

Is there a way to intervene in Kirby’s bootstrap (via a e.g. a hook) to not return the cached version from the pages cache via some conditional?

E.g. in pseudocode:

  1. Request arrives at webserver and Kirby starts bootstrap process
  2. Somewhere I’ld like to add if (true) { "do not return from pages cache, but re-render page" }
  3. Kirby continues with bootstrap but does not return the page from the pages cache, but acts as if the pages cache is not enabled

FYI: I know there are things in place at the core to e.g. discard pages cache when Cookies are used, when there are checks for active user, or when there’s an “Authorization request header”.

i think checking for the header and calling useCookie before the render should work. this should trigger the usesCookie() check as described in the docs thus disabling the caching.

$kirby = new Kirby();
if(A::get($kirby->request()->headers(), 'X-Custom')) {
    $kirby->response()->useCookie('do-not-cache-me');
}
echo $kirby()->render();

you might also be able to check for the same header inside the ignore callback.

return [
  'cache' => [
    'pages' => [
      'active' => true,
      'ignore' => fn ($page) => A::get(kirby()->request()->headers(), 'X-Custom'),
    ]
  ]
];

Thanks for the insight Bruno, I’ll give that a shot.

Howevery, ideally it would be something I could do in a plugin, without extra steps in the config…