#revalidateTag: Bust cache for a single entry?
17 messages · Page 1 of 1 (latest)
🔎 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)
const getUser = (userId) =>
unstableCache(
(userId) => getUserFromDb(userId),
[],
{ tags: [`user:${userId}`] },
)(userId);
revalidateTag(`user:${userId}`);
note that in your case, you are putting the user inside the key array, which is not the tag array, so revalidateTag("user") doesn't work.
I see, thanks!
I thought this was done by Next? From the docs:
keyParts: This is an array that identifies the cached key. It must contain globally unique values that together identify the key of the data being cached. The cache key also includes the arguments passed to the function.
so isn't adding these keys redudant?
yeah for me the keypart array is not needed most of the times, you don't really need to think about it
just think of it this way: if any strings inside the keypart array changes, then the cache is invalidated (basically)
iirc the function's string form (Function.toString() is an implicit key in that keypart array
to tag a query for revalidateTag, you need to use the tag array not the keypart array
This question has been marked as answered! If you have any other questions, feel free to create another post
[Click here](#1238073601962278992 message)
sounds a bit funky... Most of the times i want to revalidate based on the inputs of the function. your construction probably orks (still testing it),.... but its heck a verbose...
unstable_cache query keys should have an api like react-query (i.e.: string[] | args => string[])