# Snippets and cache

**URL:** <https://forum.getkirby.com/t/snippets-and-cache/15828>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 2, 2019, 2:28pm UTC](https://forum.getkirby.com/t/snippets-and-cache/15828 "2019-10-02T14:28:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/stephan/32/6611_2.png) [@Stephan](https://forum.getkirby.com/u/Stephan)\
**Post date:** [October 2, 2019, 2:28pm UTC](https://forum.getkirby.com/t/snippets-and-cache/15828/1 "2019-10-02T14:28:04Z")

</div>

I am having a problem with caching. I have closed pages for unauthorized users. These pages are cached. And it turns out that as soon as they get into the cache, they become available to everyone.

I would like to keep caching for closed pages, as they are quite “heavy”. Checking occurs in snippet init.php. Is it possible to disable caching in a snippet? 🤔

Page:

```
<?php snippet('init') ?>
<?php snippet('header') ?>

... content

<?php snippet('footer') ?>

```

and init.php

```
<?php 
if(!$kirby->user())
    go('login', 302); 
?>
```

---

<div class="post-metadata">

**Author:** ![nilshoerrmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/nilshoerrmann/32/6005_2.png) [@nilshoerrmann](https://forum.getkirby.com/u/nilshoerrmann)\
**Post date:** [October 2, 2019, 2:58pm UTC](https://forum.getkirby.com/t/snippets-and-cache/15828/2 "2019-10-02T14:58:44Z")

</div>

Is it really a good idea to cache content that actually resides behind a login? You will somehow have to protect your cache because it will otherwise leak private content.

Regarding your logic inside `init.php`: wouldn’t it be possible to move that logic to [a catch-all route](https://getkirby.com/docs/reference/router/patterns/all)?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 2, 2019, 10:28pm UTC](https://forum.getkirby.com/t/snippets-and-cache/15828/3 "2019-10-02T22:28:00Z")

</div>

Rather than using the page cache for such protected pages, I’d use a custom cache for the content that either gets the content from the cache if it exists or renders the page normally, if not, only for logged in users.
