Next.js Discord

Discord Forum

check if unstable cache is working

Answered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Golden northern bumble beeOP
Hi, how can I tell if a data request is using the cache or not? Thanks!
Answered by B33fb0n3
you can check that while doing the following:
const getCachedWhatever = unstable_cache(
  async () => {
    console.log("if you can read me, the cache missed (MISS). Else, it hits (HIT)")

    return true;
  },
  ['my-app-whatever-is-unique']
);
View full answer

24 Replies

Giant Angora
Which cache are you thinking about?
Golden northern bumble beeOP
The data cache, the one unstable cache uses
Not full route or router
Oak shoot sawfly
If you're using db orm like drizzle or prisma then you can check the logs
@Golden northern bumble bee The data cache, the one unstable cache uses
you can check that while doing the following:
const getCachedWhatever = unstable_cache(
  async () => {
    console.log("if you can read me, the cache missed (MISS). Else, it hits (HIT)")

    return true;
  },
  ['my-app-whatever-is-unique']
);
Answer
@B33fb0n3 you can check that while doing the following: tsx const getCachedWhatever = unstable_cache( async () => { console.log("if you can read me, the cache missed (MISS). Else, it hits (HIT)") return true; }, ['my-app-whatever-is-unique'] );
Golden northern bumble beeOP
I have no idea how I didn’t think of that 😂

I should see this in vercel logs right? And during dev in terminal console (since on server)?
@Golden northern bumble bee I have no idea how I didn’t think of that 😂 I should see this in vercel logs right? And during dev in terminal console (since on server)?
yes, would will see it in your serverside console. You can see it on vercel, as well as on your local server
Golden northern bumble beeOP
@B33fb0n3 I am seeing the log every time the function is called :/

Does not seem to happen with dev server, only once I deploy

any ideas?
@Golden northern bumble bee <@301376057326567425> I am seeing the log every time the function is called :/ Does not seem to happen with dev server, only once I deploy any ideas?
normally it should be the other way around. Like you would see it everytime in dev (because caching is in dev different) and not that often in production. Or did I missunderstood your message?
Golden northern bumble beeOP
No you are understanding correctly, its opposite what you would think
I am not seeing repeated logs local
@Golden northern bumble bee I am not seeing repeated logs local
can you go in production on your local server:
1. Build the app (next build)
2. Serve the app (next start)
Check the logs again
Golden northern bumble beeOP
These are the functions themselves
Will do quick demo
Only logs one time, then all gun pages share the mod data cache
So next start is how it behaves in prod?
Looks like on prodcution its starting to work, only sometimes its logging now
but they all share the same function so I am not sure about why some are not using it, 24hr cache so def not expiring 🤷‍♂️
I'll continue to monitor, does the site feel fast to yall?

(https://tarkov.directory/guns)
@Golden northern bumble bee So `next start` is how it behaves in prod?
yes, next start with next build is the production enviorement. In the dev enviorement the caching is different then in production. So yea, one warning (when the DB is requested) and then the cache was used
Now it’s good