Skip to content

Expiring cached records containing expired credentials #2495

Answered by TkDodo
viridia asked this question in Q&A
Discussion options

You must be logged in to vote

so you can definitely drive the staleTime with local state and extract it from the response, something like:

const useListImages = () => {
  const [staleTime, setStaleTime] = React.useState(0)
  return useQuery(
    key,
    queryFn,
    {
      staleTime,
      onSuccess: (data) => setStaleTime(data.expirationDate)
    }
}

but I'm not sure what good this would do in your use-case, because staleTime only specifies when a query should go from fresh to stale, which means after that time, a refetch would happen if you mount a new observer. What you maybe want would be to clear the cache after that time, and I think you'd have to spawn your own useEffect for that.

What you could also do is j…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@viridia
Comment options

@TkDodo
Comment options

@viridia
Comment options

Answer selected by viridia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants