Kirby Cache + routes

When the cache is enabled, it doesn’t look like routing takes place. I’m trying to load different content in my template depending on if a user is logged in - something that a couple other of threads here have mentioned (links below)

The site has a large number of authors and books. There’s an index page, which is best cached because it needs to parse through a lot of data. For a regular viewer, only visible items show up in the index. For a logged in user, there’s an option to show invisible items, and quick links to that item in the panel. Here’s my route and a corresponding controller:

// route in config.php
    'pattern' => 'book-index',
    'action' => function() {
      $logged_in = site()->user();
      if ($logged_in) {
        return page('/book-index/logged-in');
      } else {
        return page('/book-index');

// controller for index.php template

return function($site, $pages, $page) {
  $logged_in = ($site->user()) ? true : false;
  return array(
    'logged_in' => $logged_in,

The template then outputs the necessary info if the user is logged in.

Anyway - when the cache is disabled, it works perfectly. But, when the cache is enabled, none of the routing takes place. Is there any way to enable the routes before caching?

Maybe you should not have cache activated when logged in?

Replace your cache in config.php with this:

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

I had tried this, and it didn’t work. This does, though, and I have no idea why -

c::set('cache', true);

if(site()->user()) {
  c::set('cache', false);

In my example, make sure you don’t have c::set('cache', false); anywhere in your code. You should only have one line that involve caching, the line I wrote.

But if your code work you can use that.