# Staticache not working on posts

**URL:** <https://forum.getkirby.com/t/staticache-not-working-on-posts/31567>\
**Category:** Questions\
**Tags:** v4\
**Created:** [May 8, 2024, 11:39am UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567 "2024-05-08T11:39:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevq](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kevq/32/13682_2.png) [@kevq](https://forum.getkirby.com/u/kevq)\
**Post date:** [May 8, 2024, 11:39am UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/1 "2024-05-08T11:39:04Z")

</div>

Hey folks,

I have an issue where my cache isn’t working for post because of a model I use. I remove the `/blog/` part of my posts with a model ([see this forum thread for details](https://forum.getkirby.com/t/remove-blog-from-the-url/29487)). Since then I’ve changed `url()` for `cleanurl()` so wherever I call `cleanurl` it gives me the url without `/blog/`.

That works great, but because of this model, caching isn’t working. If I visit my homepage, I see the comment at the bottom of the html that confirms it’s cached. If I go to a “cleanurl” there’s no cache. However, if I add /blog/ to the url, I see the cache.

Here’s an example:  
No cache: [Mastodon Is DDoSing Me | Kev Quirk](https://kevquirk.com/mastodon-is-ddosing-me)  
Cache: [Mastodon Is DDoSing Me | Kev Quirk](https://kevquirk.com/blog/mastodon-is-ddosing-me)

So I now either need to fix the caching issue so that cleanurls are cached (my preferred method) or somehow revert the entire cleanurl change and go back to using /blog/ in my URLs. If go down this route though, I’ll need a way to automatically redirect children of the blog page from the cleanurl to the /blog/ url.

Any advice is very welcome at this point.

Thanks,

Kev

---

<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:** [May 8, 2024, 12:55pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/2 "2024-05-08T12:55:20Z")

</div>

Instead of creating a new method for the url, try overwriting the url method in a page model

---

<div class="post-metadata">

**Author:** ![kevq](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kevq/32/13682_2.png) [@kevq](https://forum.getkirby.com/u/kevq)\
**Post date:** [May 8, 2024, 1:29pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/3 "2024-05-08T13:29:55Z")

</div>

I got some time away from the keyboard, walked the dogs and cleared my head. Came back, read this, and knew exactly the change I needed to make. Thanks Sonja.

---

<div class="post-metadata">

**Author:** ![kevq](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kevq/32/13682_2.png) [@kevq](https://forum.getkirby.com/u/kevq)\
**Post date:** [May 8, 2024, 2:19pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/5 "2024-05-08T14:19:12Z")

</div>

I’ve just gone to write a new post, but I can no longer preview drafts, I get a 404. I assume it’s something to do with the edited route. Here’s what it looks like:

```auto
// Make the non /blog/ URLs work
        [
            'pattern' => '(:any)',
            'action' => function($uid) {
                $page = page($uid);
                if(!$page) $page = page('blog/' . $uid);
                if(!$page) $page = site()->errorPage();
                return site()->visit($page);
            }
        ],
        [
            'pattern' => 'blog/(:any)',
            'action' => function($uid) {
                go($uid);
            }
        ],

```

Is there something I can do to exclude drafts from this route, or (better yet) include them in it?

Tried [this solution](https://forum.getkirby.com/t/getting-404-when-page-is-a-draft/22809) but it didn’t work for me.

Thanks.

---

<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:** [May 8, 2024, 6:55pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/6 "2024-05-08T18:55:08Z")

</div>

> [@kevq](#):
>
> Tried [this solution](https://forum.getkirby.com/t/getting-404-when-page-is-a-draft/22809) but it didn’t work for me.

Could you please post exactly what you tried?

---

<div class="post-metadata">

**Author:** ![kevq](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kevq/32/13682_2.png) [@kevq](https://forum.getkirby.com/u/kevq)\
**Post date:** [May 8, 2024, 7:15pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/7 "2024-05-08T19:15:07Z")

</div>

Sorry, yeah. I changed

```auto
 $page = page($uid);

```

to

```auto
$page = kirby()->page($uid);

```

---

<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:** [May 8, 2024, 7:36pm UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/8 "2024-05-08T19:36:52Z")

</div>

Did you also change that for this second line

> [@kevq](#):
>
> ` if(!$page) $page = page('blog/' . $uid);`

---

<div class="post-metadata">

**Author:** ![kevq](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kevq/32/13682_2.png) [@kevq](https://forum.getkirby.com/u/kevq)\
**Post date:** [May 9, 2024, 7:43am UTC](https://forum.getkirby.com/t/staticache-not-working-on-posts/31567/9 "2024-05-09T07:43:27Z")

</div>

Doh! That worked, thanks Sonja.
