Disabling cache in useShow

How can one always ensure that the resource is not cached ?
3 Replies
kapa.ai
kapa.ai5mo ago
Hi @i.stoica. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Refine's data hooks, including useShow, cache queries by default. This means that if you perform a query for a resource, the result will be cached and the next time you perform the same query, the results will be returned immediately from the cache. If the data is considered stale, the query will be refetched in the background. However, if you want to disable the caching and always fetch the data, you can use the useInvalidate hook. This hook allows you to manually invalidate the queries based on your conditions. Here is an example of how you can use it:
import { useInvalidate } from "@refinedev/core";

const invalidate = useInvalidate();

useForm({
resource: "categories",
action: "edit",
id: 1,
invalidates: false,
onMutationSuccess() {
invalidate({
resource: "posts",
invalidates: ["resourceAll"],
});
},
});
import { useInvalidate } from "@refinedev/core";

const invalidate = useInvalidate();

useForm({
resource: "categories",
action: "edit",
id: 1,
invalidates: false,
onMutationSuccess() {
invalidate({
resource: "posts",
invalidates: ["resourceAll"],
});
},
});
In this example, the invalidates prop of the useForm hook is set to false, which disables the default invalidation. Then, the useInvalidate hook is used to manually invalidate the queries after a successful mutation. Please note that this is just an example and you might need to adjust it according to your specific use case. For more information, you can refer to the Refine documentation on Invalidation (https://refine.dev/docs/guides-concepts/forms#invalidation-). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@180601470268211200> kapa.ai is still learning and improving, please let us know how it did by reacting below
foreign-sapphire
foreign-sapphire5mo ago
How can invalidation be performed using useShow ?