T
TanStack•2y ago
fascinating-indigo

clear persisted cache from sessionStorage

Im trying to implement sessionStorage and want to clear all after logout, what is the way to go for this?
const queryClient = new QueryClient({
defaultOptions: {
queries: {
gcTime: 1000 * 60 * 5, // 5 minutes
persister: experimental_createPersister({
storage: sessionStorage,
maxAge: 1000 * 60 * 60 * 12, // 12 hours
}),
},
},
});
const queryClient = new QueryClient({
defaultOptions: {
queries: {
gcTime: 1000 * 60 * 5, // 5 minutes
persister: experimental_createPersister({
storage: sessionStorage,
maxAge: 1000 * 60 * 60 * 12, // 12 hours
}),
},
},
});
everything gets persisted nicely but when i logout i want to do:
const logout = useMutation({
mutationFn: () => authService.logout(),
onSuccess: async () => {
queryClient.clear()
}
})
const logout = useMutation({
mutationFn: () => authService.logout(),
onSuccess: async () => {
queryClient.clear()
}
})
but this doesn't reset the sessionStorage, what is the best way to do this? or do we just do
sessionStorage.clear();
sessionStorage.clear();
2 Replies
flat-fuchsia
flat-fuchsia•15mo ago
@andredewaard Were you able to find the solution? cc @TkDodo 🔮
fascinating-indigo
fascinating-indigoOP•15mo ago
I just do the sessionStorage.clear() method to be sure it’s removed.

Did you find this page helpful?