Next.js Discord

Discord Forum

Can the revalidate time on unstable_cache be dynamic, based on the data it is cached?

Unanswered
Champagne D’Argent posted this in #help-forum
Open in Discord
Avatar
Champagne D’ArgentOP
I basically want to achieve this:

const getCachedCurrentYear = unstable_cache(
  async function getCurrentYear() {
    const thisYearsMeeting = await database.getCurrentYear();

    if (!thisYearsMeeting) {
      redirect("/inactive");
    }

    const cacheTimeInSeconds = calculateRevalidationTime(thisYearsMeeting);
    // Can I set cache to cacheTimeInSeconds?

    return thisYearsMeeting;
  },
  [],
  {
    revalidate: 3600 * 24, // 1 day
    tags: ["current-year"],
  }
);

and have the revalidate time not be 1 day, but rather cacheTimeInSeconds. Is this doable?

1 Reply

Avatar
Champagne D’ArgentOP
bump!