Next.js Discord

Discord Forum

Partial Matching Cache Tags

Unanswered
Alaskan Husky posted this in #help-forum
Open in Discord
Alaskan HuskyOP
Is it possible to define a tag cacheTag(["foo", 1]) and revalidate it with just revalidateTag(["foo"]) ?

3 Replies

@alfonsüs ardani you can [attach tags as many as possible](<https://nextjs.org/docs/app/api-reference/functions/cacheTag#creating-tags-from-external-data>) but you would only need one tag to revalidateTag
Alaskan HuskyOP
is there a difference between

cacheTag(["foo", "bar"])


and
cacheTag(["foo"])
cacheTag(["bar"])


or is it safe to call cacheTag multiple times? or will that have any problematic implications?
Pacific sand lance
first of all - cacheTag has following signature: function cacheTag(...tags: string[]): void so passing array should result in type error. looking at implementation, cacheTag("foo", "bar") should work in same way ascacheTag("foo"); cacheTag("bar").

since revalidateTag accepts single tag and profile, you can do something like cacheTag("foo", "foo:" + some identifier). then calling revalidateTag("foo") should invalidate all resources that included "foo" in cache tags.