The big problem computing page numbers was in discourse-sitemap:
https://github.com/discourse/discourse-sitemap/pull/19
The problem with caching was fixed here:
https://github.com/discourse/discourse-sitemap/pull/20
I also fixed the not found issue in core (minor), where it would reply with a 200 when requesting second page, but only having 20 posts (1 page):