#Weird Cache Behaviour

7 messages · Page 1 of 1 (latest)

atomic mountain
#

I have 2 json files, /data/contentDownloads.json and /data/links.json

This is my helper to get the json files

import { unstable_cache } from "next/cache";
export async function getJson(
  fileName: string,
  tag?: string,
  revalidate?: number
) {
  const content = unstable_cache(
    async () => {
      const file = await fs.readFile(
        process.cwd() + `/data${fileName}.json`,
        "utf8"
      );
      const locContent = JSON.parse(file);
      return locContent;
    },
    ["json"],
    {
      tags: tag ? [tag] : ["data"],
      revalidate: revalidate ? revalidate : false,
    }
  )();
  return content;
}

I need the tags so I can revalidate them. Now if I call the function with /contentDownloads, "content" I get the correct data and can also revalidate correctly, but doing "links", "link" provides the same data as the content one, any idea why this seems to be happening?

coral vineBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

tawdry python
#

so "content" and "link" uses the same cache since the stringified version of the async function is the same

#

either put fileName in the second parameter, or pass it as an argument again into the inner function

atomic mountain
#

I thought that param didn't matter lol