Processing of Twig and caching

I would like to hide or show parts of a page depending on whether a user is logged in or not. Based on what rhukster suggests in Hiding parts of pages I use something like:
—twig
{% if grav.user.authorize(‘site.login’) %}
This is text only logged users can see.
{% endif %}

This works fine when caching is disabled. However when caching is enabled it does not work. The previously cached page content gets output even though `process: twig: true` is set in the page header. This is the front matter for the (modular) page:
---yaml
title: live
published: true
process:
    twig: true
    markdown: false
routable: false
cache_enable: true
visible: false

The crude way is to disable caching completely but I keep hoping to find a way to serve cached content to non logged in users (anonymous visitors) for performance reasons.
Again any help is much appreciated!

From how I understand the life cycle, the cache check is too early for the process: twigsetting to matter. To do what you ask, I think you’d have to disable the global cache and write a plugin to manage the cache itself (which is theoretically possible; the API is exposed). The problem is that the concept of “logged in” is not a part of the core code. It’s a plugin.

Maybe a dev will have another idea. I’m not sure this idea would work right now because there may not be event hooks in the right places.

I was already beginning to think this was a hard nut to crack and so it appears to be.
Not as a developer nor as an architect, I do think security should be in the a core. Of course, with the possibility to extend it’s functionality using plugins.
For now I will pursue witch caching disabled. Grav is so fast I hardly notice any difference with or without caching enabled. Many thanks!