Next.js Discord

Discord Forum

Unstable cache wrapper

Unanswered
Sphecid wasp posted this in #help-forum
Open in Discord
Sphecid waspOP
I want to reuse unstable cache in different places with different input for same cached function. Is this correct implementation?

It will be used in static pages to use on demand revalidation for tags to rebuild only certain pages
export function cachedOptions(ids: string[]) {
    return unstable_cache(
        async (ids: string[]) => {
            return data
        },
        [],
        {
            tags: ids.map((id) => `options/${id}`),
        },
    )(ids)
}

0 Replies