500 when disabling cache for logged users

Hi guys!
Currently I am running kirby 2.5.8 and would like to disable cache for logged in users. When using this code I am getting a blank page with a 500 error. What would be best practice for that?

 $logged_in = site()->user();
  if ($logged_in) {
      c::set('cache', false);
  } else {
      c::set('cache', true);
  }

Thanks in advance!

1 Like

I guess you are using a multi-lang installation? The problem is that you can’t use site() in your config.

Hey @texnixe, thanks for the quick response!

Yes, I am using a multi lang set up.

Is there a workaround I could try in order to make this work?

Thanks!

@texnixe Is there a way to check for the existence of a login session from the config? Sounds like you don’t care who person is, just that are currently logged in.

@krstnschwpwr You can add this in your config. Seems to work but I don’t know if it has any implications.

s::start();
c::set('cache', isset($_SESSION['kirby_auth_username'])?false:true);