Cache is patchy

Hi,

I may be misunderstanding how the cache works for Kirby, but here goes. I have implemented the page cache, using this block in the config file:

'cache' => [
      'pages' => [
          'active' => true,
          'ignore' => function ($page) {
            return $page->pageBuilder()->toBlocks()->filterBy('type', 'full-newsletter-signup-form')->isNotEmpty();
          }
      ]
    ],

Which I think should cache every page, apart from those with the page builder, where the full-newsletter-signup-form block has been used. I have tested this with a simple if statement on the pages, and it seems to be returning true/false on the right pages.

However, when I look at the cache there are only a few pages in there, not all the ones I would expect. What triggers a page being added? I have visited them in browser but that doesn’t seem to have done it

A page is cached when you visit it in the browser. The cache is completely deleted when you make a change somewhere.

Thanks for the reply, that is what I thought. For some reason only some pages are being cached, though I think my function is doing what it should. I will keep at it

Ok I can’t work this out. For some reason subpages in my news directory are being cached, but all others are not. I have dropped my function in the header of all my pages like so:

if($page->pageBuilder()->toBlocks()->filterBy('type', 'full-newsletter-signup-form')->isNotEmpty()):
  echo "this page will be ignored";
else:
  echo "this page will be cached";
endif;

And that is doing what I would expect, it is saying a page will be cached if (a) it doesn’t have the pagebuilder field or (b) it has it, but doesn’t use the full-newsletter-signup-form block.

Have you tried to watch the cache folder while you are trying to open each page? Is the complete cache cleared at some point maybe due to updates happening in the background, e.g. hooks or models or pluins that update something, thus clearing the cache?

I tested the cache in a fresh Starterkit with slightly adapted code (because the starterkit doesn’t have your custom block. So in config, I put this:

return [
    'debug' => true,
    'cache' => [
        'pages' => [
            'active' => true,
            'ignore' => function ($page) {
              return $page->text()->toBlocks()->filterBy('type', 'image')->isNotEmpty();
            }  
        ]
      ],
];

And all pages but the notes/exploring-the-universe page which has an image block were cached as expected.

Hi,

Sorry for the delayed reply. I have watched the cache folder while navigating the site, and only the subpages in the /news section are cached, all others are not.

I don’t have any hooks on this site, I have some fairly simple controllers to handle Uniform submissions but not anything beyond that.

The only plugin I have that would affect the cache (I think) is the Fingerprint plugin - GitHub - bnomei/kirby3-fingerprint: File Method and css/js helper to add hash to files. I use this for cachebusting CSS and JS.

Hm, can’t tell from here what is happening. Feel free to send me a download link to your project via PM if you can, then I could take a look to see if I can find the issues.

1 Like