Cannot cache paginations?

Hello,
I happend to find a small issue.
I have a page that displays the whole blog post list, and it has a pagination section that enables a function of switching pages in url (eg. https://whatever.me/blog/page:3), but it failed to work when I switched on cache function with driver of memcached.
Is there a way to solve the problem?
Thanks!

It does not make sense to cache paginated pages becuase they are dynamic, and you never know how many there are. In the case of a blog, for example, when you add new pages, they wont show up because of the cache. You either need to exclude the blog from the cache, or flush and rebuild the cache when you post a new blog post.

So, is there a way to speed up rendering of the blog post list page, if there are hundreds of posts?
By the way, can I use regular expression to set the ignore option in config?
All thanks!

You can ignore pages by name, and probably by using a filter instead, to ignore pages with a particular template. It’s explained in the docs.

Then I want to ask a small question.
The structure for my website is like this,

  • blog
    • note
    • post1
    • post2
    • discovery
    • experiment

And I wanted to cache the whole blog page and its children.
Is there a covenient way to write in the config file apart from simply listing page ids?
Thanks a lot!

It’s rather the other way round. You set caching to true in general and then you use the ignore option to exempt pages from the cache. The ignore option, however, accepts a callback, so you don’t have to pass a stupid list of IDs to ignore:

https://getkirby.com/docs/guide/cache

Long time lurker first time poster.

I am really impressed with Kirby 3 so looking into Kirby off-hours and this post attracted my attention.

Sorry if my post is considered thread-hijacking.

I got two questions:

  1. Why can paginated pages not be cached? Reason why I am asking is that other CMSs can do it. It is mentioned it is dynamic but its not like really dynamic. The cache is cleared when a new post is entered so the pagination will then reflect the new amount of post
  2. I can see I don’t need to use server rewrite for the cached files. Thats pretty cool but wondering if it would make sense to do though to bypass Kirby 100% for cached pages.

Thanks

1 Like

It has nothing to do with stuff being dynamic. Have to look if Kirby caches individual pagination pages or not. If so, I don’t see why it shouldn’t work but the original thread is not clear about what didn’t work as expected.

Should be, yes.

Edit: The pagination stops working once caching is enabled. There is already an issue on GitHub:

1 Like

Ah ha! I ran into this, which which is why i figured it wasnt working, but to me it felt like the cache wasn’t working with the page:3 type urls since they are in flux really, but now it seems its a bug …

No, they are not, only if you add new pages to the collection. In that case, the cache is flushed anyway. Otherwise, you could never cache an article list even without pagination.

If you use a query string instead of the page parameter, only the first page gets cached, all other pages are then pulled dynamically.

   $albums = $page->children()->paginate([
        'limit'    => 2,
        'method'   => 'query',
        'variable' => 'p'
      ]);

So this could be a workaround to at least cache the first page of results.

This is now fixed on the develop branch, i.e. the pages cache is automatically disabled if there’s a parameter in the URL.

1 Like