-
The query results that I am working with are records with fields that contain S3 signed urls and headers. This information includes a digitally-signed expiration date - any attempt to access the url beyond that date will generate a 403. These are used to display images. So for example, I can call the What I'd like to do is consider any record stale if it is older than the expiration date. It does no good to cache a url which can't be used. However, I don't know the expiration date when I made the query, it's up to the backend to decide how long the url is valid for, so I only know the expiration time once I get the response back. Is there a way for me to customize react-query's staleness algorithm so that it never uses a record with an expired credential stored within it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
so you can definitely drive the staleTime with local state and extract it from the response, something like:
but I'm not sure what good this would do in your use-case, because staleTime only specifies when a query should go from What you could also do is just let a refetch yield 403 and then react on it by removing the entry from the cache, or try to fetch for a different url... |
Beta Was this translation helpful? Give feedback.
so you can definitely drive the staleTime with local state and extract it from the response, something like:
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
tostale
, 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…