Disable cache for logged in users

#1

Hello guys,

In Kirby 2 i could disable the cache for logged in user with the following code

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

What is the right way to do this in K3?

1 Like
#2

There is an issue in the ideas repro:

[Cms] Don’t cache requests of logged-in users #40

I don’t know, if it is the same issue.

#3

This problem that you describe in the issue exactly where i struggle with, hope it will be solved soon.

1 Like
#4

I want to turn off the if the cache if the cookie kirby_session exist, isset is not the right way. What would work?

  'cache.pages' => [
    'active' => isset(Cookie::exist('kirby_session'))?false:true,
    'ignore' => array('error', 'contact'), 
    ],
#5

There are some issues here:

  • the method is called exists not exist, i.e. with a s at the end
  • you can’t use isset(), so Cookie::exists('kirby_session') ?? false would be enough
  • but, it doesn’t help with what you want to achieve, because the session is not only created when the user is logged in.
#6

unless you have some other frontend logic getting kirby()->user()might do the trick. problem is that you can not do that in the config and using a closure is not supported (yet). but that could be done as easy as for the ignore option. you could file an idea issue for that.