Next.js Discord

Discord Forum

Does passing keyParts to unstable_cache overwrite the default cache key generation?

Unanswered
Snowshoe posted this in #help-forum
Open in Discord
SnowshoeOP
I’m trying to use unstable_cache in Next.js 15 with revalidate, but I’m unsure how keyParts affects the cache behavior.

If I pass something like ["myKey"] as keyParts, does that overwrite the default cache key (based on function arguments + stringified function), or does it combine with it?

And if it does overwrite, should I pass undefined or just omit keyParts entirely to make sure it uses the default key generation and still allow passing { revalidate: 3600 }?

1 Reply

It appends your keys to the ones Next.js automatically generates from the function signature (the function itself and its arguments) by default.

If I remember correctly, you shouldn’t need to provide anything here for most cases, only when your function depends on external variables, that don’t come as parameters.