TanStackT
TanStack2y ago
2 replies
slow-yellow

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
      }),
    },
  },
});


everything gets persisted nicely but when i logout i want to do:
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();
Was this page helpful?