kirby-meta icon indicating copy to clipboard operation
kirby-meta copied to clipboard

Sitemap cache not working with getkirby/staticache plugin

Open bnomei opened this issue 1 year ago • 9 comments

CleanShot 2023-03-08 at 19 48 38

1.) key should not contain a dot since the staticache uses that instead of / https://github.com/getkirby/staticache/blob/9ef2d7195b5c8212fcf53194407cc28aec0e3901/src/StatiCache.php#L144

2.) i think the data set should not be a string but an array. https://github.com/getkirby/kirby/blob/9ecd11cd5b7d4875d4212f767a2b3ad3e52b3528/src/Cms/Page.php#L1030

BUT the staticache plugin expects a real page object (cache key => page id) so it will all fail anyway https://github.com/getkirby/staticache/blob/9ef2d7195b5c8212fcf53194407cc28aec0e3901/src/StatiCache.php#L106

how to fix this? add a plugin cache and check for staticache plugin but match array for pages cache just to be safe

App::plugin('fabianmichael/meta', [
    'options' => [
       //...
        'cache' => true,
    ],
$routes[] = [
        'pattern' => 'sitemap.xml',
        'action' => function () use ($kirby) {
            if ($kirby->option('fabianmichael.meta.sitemap') === false && SiteMeta::robots('index') === false) {
                $this->next();
            }

            $sitemap = [];
            $cache = $kirby->cache(
+                option('cache.pages.type') !== 'static' ? 'pages' : 'fabianmichael.meta'
            );
            $cacheKey = 'sitemap.xml';

            if (option('debug') === true || ! ($sitemap = $cache->get($cacheKey))) {
                $sitemap = Sitemap::factory()->generate();
+              $cache->set($cacheKey, [
+                    'html' => $sitemap,
+               ]);
            }

            return new Response($sitemap, 'application/xml');
        },
    ];

bnomei avatar Mar 08 '23 20:03 bnomei