Partial Matching Cache Tags
Unanswered
Alaskan Husky posted this in #help-forum
Alaskan HuskyOP
Is it possible to define a tag
cacheTag(["foo", 1]) and revalidate it with just revalidateTag(["foo"]) ?3 Replies
@Alaskan Husky Is it possible to define a tag `cacheTag(["foo", 1])` and revalidate it with just `revalidateTag(["foo"]) ` ?
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
@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
and
or is it safe to call cacheTag multiple times? or will that have any problematic implications?
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 -
since
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.