How to check caching?

Is there a simple way to make visible whether a page was rendered freshly or obtained from Kirby’s cache? A class ‘cached’ applied to the body tag would serve the purpose nicely.

Why this question? I’m chasing some weird problems that may or may not have to do with caching. It would help a lot to easily see whether the cache was involved in a given moment.

I’d check out the $page->render() function for the conditions when a page is rendered from cache (for the page cache, that is). Then you can create a custom isRenderedFromCache() function from this information.

Other than that, it might be easier to just disable the cache for that page to see if the issue persists.

Thanks, Sonja.

If anybody is interested:
As suggested, I ended up temporarily patching Kirby’s Page class (kirby/src/Cms/Page.php; ->render()).
I added a hook, which I called “page.cache.render:after”. It triggers when Kirby renders the page from its file-cache.

This is the patch (line 1047):

// fetch the page regularly
if ($html === null) {
... // as is
} else {
	$html = $kirby->apply('page.cache.render:after', [
		'contentType' => $contentType,
		'data'        => $kirby->data,
		'html'        => $html,
		'page'        => $this
	], 'html');
}

Actually, I wonder whether such a new hook might be useful in general. Just an idea.