Server Actions: APIs for sophisticated cache revalidation strategies #50043
Replies: 2 comments 3 replies
-
Actually, having to call revalidateTag multiple times is very inconvenient. |
Beta Was this translation helpful? Give feedback.
-
I think I have the same problem as this, but I'm not sure I understand your solution. If I fetch all posts on page load, at the moment the full set of posts would be stored to the cache. If someone then edits We'd need to purge and refetch the entire posts object. For me, I'm hoping to save edits every time a user finishes editing an atom of data (e.g. For me, the solution seems to either be
Since you asked this back in May though, did you ever find anything else out that helped solve your use case? |
Beta Was this translation helpful? Give feedback.
-
Hi,
the
13.4
release blogpost introduced arevalidateTag
API, which allows resetting the cache for a given tag. I am hereby requesting an API, that returns all existing cache keys.The motivation is quite simple: For sophisticated cache revalidation strategies, it is impossible to know what cache keys should be revalidated without actually knowing which exists. As an example, you might query all posts from a
post
table in one component, and the details of one post in another. The cache tags would then contain thepost
table, and, for the latter, the id of the post, e.g.["post", "id=123"]
. Or,["post?id=123"]
. When I update one post within a server action, I can only revalidate both queries withrevalidateTag('post')
. For larger apps, this leads to a lot of unnecessary revalidation.To enable more sophisticated revalidation strategies, we would need at least one of:
getAllCachedQueries()
to return all active cached queries with their tags (returns an array of arrays, with one array of tags for each query)getAllCacheTags()
to return all active cache tagsTo further improve the DX:
revalidateTags(["post"])
to revalidate a set of tags.revalidateQueries(["post", "id=123"])
to revalidate all queries that have all of the passed cache tags. In this example, only the detail query would be revalidated.Best
Philipp
Beta Was this translation helpful? Give feedback.
All reactions