Skip to content
Discussion options

You must be logged in to vote

I see what you're asking now.. you want unstable_cache to always return cached data immediately, even after the revalidate period, and only update in the background.

Try this:

const cache = new Map(); // Replace with a more persistent cache if needed

const getCachedMapData = async (filePath) => {
  const cacheKey = `voxel_${filePath}`;
  const cachedEntry = cache.get(cacheKey);

  if (cachedEntry) {
    // If cache exists, return immediately & revalidate in the background
    if (Date.now() < cachedEntry.expiry) {
      return cachedEntry.data;
    } else {
      revalidateInBackground(filePath, cacheKey);
      return cachedEntry.data; // Serve stale data
    }
  }

  // First load: Blo…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sunnypatell
Comment options

Answer selected by TreeOfSelf
Comment options

You must be logged in to vote
2 replies
@sengirab
Comment options

@TreeOfSelf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants