Skip to content

fix: add 30s TTL to pMemoize sitemap cache#7

Open
mabdullahabid wants to merge 1 commit intoabd.devfrom
fix/sitemap-pmemoize-ttl
Open

fix: add 30s TTL to pMemoize sitemap cache#7
mabdullahabid wants to merge 1 commit intoabd.devfrom
fix/sitemap-pmemoize-ttl

Conversation

@mabdullahabid
Copy link
Owner

Problem

New blog posts published to Notion take a long time to become accessible (showing Page404) even after multiple visits.

Root cause: pMemoize in lib/get-site-map.ts has no maxAge, so it caches the Notion sitemap indefinitely in-process. Vercel keeps serverless function instances warm for 30-60 minutes. Any new Notion page published after a function instance boots is invisible to that instance until it cold-starts.

Fix

Add maxAge: 30_000 (30 seconds) to the pMemoize call. After 30 seconds, the sitemap cache expires and the next request fetches a fresh sitemap from Notion — picking up any newly published pages.

// before
const getAllPages = pMemoize(getAllPagesImpl, {
  cacheKey: (...args) => JSON.stringify(args)
})

// after  
const getAllPages = pMemoize(getAllPagesImpl, {
  cacheKey: (...args) => JSON.stringify(args),
  maxAge: 30_000 // 30s TTL — prevents stale sitemap cache on warm serverless instances
})

Testing

  1. Merge to abd.dev branch
  2. Publish a new page to Notion Blog Posts DB
  3. Visit the URL within ~30 seconds — should resolve instead of showing Page404

One line diff. No other changes.

Without a maxAge, pMemoize caches the Notion sitemap indefinitely
in warm serverless function instances (30-60min on Vercel). New pages
published to Notion are invisible until all instances cold-start.

Adding maxAge: 30_000 ensures the sitemap refreshes every 30s,
matching the ISR revalidate: 10 cadence on [pageId].tsx.
@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
abd.dev Ready Ready Preview, Comment Mar 5, 2026 9:00pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant