# Kirby Cache + routes

**URL:** <https://forum.getkirby.com/t/kirby-cache-routes/2032>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 16, 2015, 9:07pm UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032 "2015-09-16T21:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [September 16, 2015, 9:07pm UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032/1 "2015-09-16T21:07:57Z")

</div>

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:

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

```

```auto
// 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?

> [@Questions about Kirby file cache](http://forum.getkirby.com/t/questions-about-kirby-file-cache/1823):
>
> My site was getting slow because of some heavy parsing stuff. I’m trying out the Kirby Cache. It works fine I just have some questions about it that I could not find any answers to in the docs. 1. When do cache refresh? When does the cache refresh? On page save? On expire date? Something else? 2. Does it cache when logged in? Does Kirby cache pages when I’m logged in to the panel? (on the front end) Update - Answer The answer is yes, it caches pages even if logged in. 3. Cache html timestamp…

[http://forum.getkirby.com/t/possibility-to-turn-off-the-cache/658](http://forum.getkirby.com/t/possibility-to-turn-off-the-cache/658)

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 17, 2015, 8:11am UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032/2 "2015-09-17T08:11:58Z")

</div>

Maybe you should not have cache activated when logged in?

**Replace your cache in config.php with this:**

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

```

---

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [September 17, 2015, 8:18pm UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032/3 "2015-09-17T20:18:46Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 18, 2015, 5:54am UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032/4 "2015-09-18T05:54:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/kirby-cache-routes/2032/5 "2025-02-06T17:00:29Z")

</div>


