Cache Revalidation
When using the application, we often encounter the need to revalidate data
. This is because of various
dynamic changes
in the case of the users interacting with our applications. For example, when deleting a note from the
list of notes in the database, we want the already stored data to be refreshed. In this case, we use cache revalidation.
We can do it by using appropriate methods. Passing an invalidationKey
which should be a cacheKey or RegExp
that
will allow us to find the desired key of the data stored in cache.
- React
- Typescript
// With useFetch
const { revalidate } = useFetch(getUsers);
// Refresh used command
revalidate()
// or
revalidate(getNotes)
// or
revalidate(getNotes.cacheKey)
// or
revalidate(new RegExp(...))
// With useSubmit
const { revalidate } = useSubmit(getUsers);
revalidate(getNotes)
// or
revalidate(getNotes.cacheKey)
// or
revalidate(new RegExp(...))
// With useCache
const { revalidate } = useCache(getUsers);
// Refresh used command
revalidate()
// or
revalidate(getNotes)
// or
revalidate(getNotes.cacheKey)
// or
revalidate(new RegExp(...))
builder.cache.revalidate(getNotes.cacheKey)
// or
builder.cache.revalidate(new RegExp(...))