How to cache "only" the webpages for anonymous visitors

I look for the possibility to cache “only” the webpages for anonymous visitors, who are not logged in within Kirby nor panel.
Every logged in user shall always get the same page as a “new” rendered page, but the cache directory must not be deleted at the same time.
Every anonymous visitor shall get a cached page, if this page exists in the cache directory.
Only the pages for anonymous visitors have to be saved in the cache directory.

Explanations:

  • In my website, the most pages for logged in users (this are only a few people) show some content, that anonymous visitors (that are many people) do not see.
  • I do not know, if I have overlooked a cache option or setting, but I have not found the right switch.
  • I think such an option would speed the website.

Thanks for your help!

I’m not sure I understand this correctly. So you have public pages you want to cache and private pages that you don’t want to cache? Or are there also pages which are public, but should not be cached for logged in users.

You can exclude individual pages from caching, but you cannot have the same page in the cache and not in the cache depending on visitor status.

On the most public webpages is a second (internal) menu only for logged in users.
Therefore the same webpage looks different, if a logged in user or an anonymous visitor looks at it.

As I mentioned in the other topic regarding the cache, as soon as a single page is updated, the complete cache is flushed anyway.

Have you tried something like this in your config.php:

if (! site()->user()) {
  c::set('cache', true);
}