Pages with protected content cannot be cached

Hi Sonja!

In my config.php, to activate cache for all pages, I currently have this:

'cache' => [
  'pages' => [
    'active' => true
  ]
],

Cache is working fine (at this step). In the header response I have:

  • For visitors: Cache-Control: max-age=0
  • For logged in users: Cache-Control: no-store, private

But in any template or snippet, if I want to make some content visible for logged in users only, once I use let’s says this:

<?php if ( $kirby->user() ):
  "Hello dear member"
<?php endif ?>

… the header response for visitors become Cache-Control: no-store, private.

I tried many things to make cache work, like I explained previously, even some hacks like the one shared here by @sebastiangreger. The issue has even been reproduced today by @sylvainjule using the latest Starterkit (3.7.5), as described in this Github post
So I’m not the only one struggling with cache when pages contain user checks to display protected content :exploding_head:

HOWEVER, I just noticed that in the .htaccess file (the one inlcuded in the Starterkit and Plainkit), if I remove the following line, caching seems to work as expected for visitors:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

I said “seems to work” because I don’t know if it’s not breaking or going to break something in the way Kirby uses authorization… Maybe @lukasbestle, @bnomei or even @bastianallgeier could share their input? (Sorry guys for pinging, hope you won’t by angry :sweat_smile:)

Again, thanks all for your time and effort helping solve this issue :smiling_face: