Skip to content

Conversation

@jcwillox
Copy link

I'm trying to use bentocache in a serverless environment, however, to properly take advantage of the "grace" (swr) functionality background promises need to be registered with waitUntil so they don't get terminated. I've added support for that, in the two places I think it needed, and it seems to be working correctly on my website. Let me know if you want any changes, or think I missed anything.

I got copilot to generate a summary.

Summary

This pull request introduces support for registering background tasks in serverless environments via a new waitUntil option in BentoCache. This is essential for enabling background cache revalidation (SWR) in platforms like Vercel and Cloudflare Workers, ensuring that background tasks can complete even after the main response is sent. The documentation has been updated to explain how and when to use this option, and example usage is provided for common serverless platforms. Additionally, minor formatting and consistency improvements were made to the documentation.

Serverless background task support:

  • Added a new waitUntil option to BentoCache (RawBentoCacheOptions, BentoCacheOptions) to allow registration of background tasks, enabling proper SWR (Stale-While-Revalidate) behavior in serverless environments. This option is now called in relevant code paths when background revalidation is triggered. [1] [2] [3] [4] [5]

Documentation updates:

  • Updated docs/options.md to document the new waitUntil option, including explanations, usage scenarios, and code examples for Vercel and Cloudflare Workers.
  • Minor formatting and consistency improvements in code examples and option descriptions in the documentation. [1] [2] [3]

@changeset-bot
Copy link

changeset-bot bot commented Jan 12, 2026

🦋 Changeset detected

Latest commit: 20859d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bentocache Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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