Cannot exclude sitemap from cache

I’m using @pedroborgesKirby XML Sitemap plugin, but want to exclude it from being cached. I have tried both of the following cache.ignore settings, but there is still a cache file named sitemap being created.

c::set('cache.ignore', array('sitemap'));
c::set('cache.ignore', array('sitemap.xml'));

Am I missing something obvious?

I think the cache ignore only excludes pages that are in the content folder.

Look at lines 30-32 in the plugin, it looks like it checks the cache before generating a new sitemap.

if (cache::exists('sitemap')) {
     return new response(cache::get('sitemap'), 'xml');
}

and line 73…

cache::set('sitemap', $sitemap);

I think if you comment those lines out, it will always generate a new sitemap and not serve the cached one.

I’m not sure that having it cached is an issue though because I believe the cache gets updated when a page changes, which means the cached sitemap should be updated automatically.

@pedroborges is there a better way to keep the sitemap out of the cache without modifying the plugin?

You config should look like this:

c::set('cache.ignore', array('sitemap', 'sitemap.xml'));

Otherwise, your second setting overwrites the first.

That’s interesting, seeing as the sitemap gets cached in the first place. You would think that the ignore would apply across the board.

I was using one of the settings in the config at a time, so it wasn’t getting overwritten.

I’ll try adding both to the array and see if it helps.

I don’t think it will work, as the code in the plugin does not respect the cache.ignore settings. However, I agree that this setting might be irrelevant, because Kirby flushes the complete cache whenever a page is changed via the Panel.

That is true, but I’m not using the panel on this particular site.

I’ll likely have to set up a cron job to flush the cache daily, unless @pedroborges can adjust the plugin to work with the cache.ignore settings.

I think you can do that yourself by wrapping the cache::set() command in an if statement and create a pull request.

I’ll look into doing that … thanks.

BTW: How do you flush the cache in general if not using the Panel?

I usually delete the contents of the site/cache directory (or just delete the sitemap cache file) using my FTP client.

Also, when I edit and upload individual content files, Kirby’s cache of that file updates automatically. So I don’t worry about having to manually flush the cache for content files. It’s the sitemap that’s being sticky.