#dynamically base unstable_cache tags from result

1 messages · Page 1 of 1 (latest)

zenith robinBOT
#

Hi @limpid urchin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the provided knowledge sources, I don't have enough information to directly answer whether you can dynamically base unstable_cache tags from the result. The documentation doesn't explicitly mention this capability.

However, I can provide some relevant information about unstable_cache and its usage of tags:

The unstable_cache function in Next.js allows you to cache the results of expensive operations and reuse them across multiple requests. It accepts three parameters: the function to cache, an array of key parts, and an options object Next.js Docs: unstable_cache (https://nextjs.org/docs/app/api-reference/functions/unstable_cache).

In the options object, you can specify tags:

const getCachedUser = unstable_cache(
  async (id) => getUser(id),
  ['my-app-user'],
  { tags: ['user-tag'] }
);

The tags are used for cache invalidation. You can use the revalidateTag function to purge cache entries associated with a specific tag Next.js Docs: Caching in Next.js (https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag).

While the documentation doesn't explicitly state whether you can dynamically set tags based on the result, it's worth noting that the tags are specified in the options object when defining the cached function, not after the function has executed.

If you need more specific information or a definitive answer about dynamically setting tags based on the result, you might want to consult the Next.js documentation directly or reach out to the Next.js community for more detailed insights.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: