T
TanStack2y ago
narrow-beige

Best practice for auditing requests?

Hi all. We have had requested that all API requests to certain endpoints create audit records. This is done for each request. You can see how this might get out of hand with the refetching that is done by default. While that can be configured on a per-query basis, I'm wondering if anyone else has had to support something like this and how you have gone about it. Thanks.
4 Replies
fair-rose
fair-rose2y ago
You can see how this might get out of hand
no, I don't. please be more specific with what you mean here. What gets out of hand how?
narrow-beige
narrow-beigeOP2y ago
I want to make sure the user has up to date information but I don't want to flood our audit records. A user switches tabs for a second? Refetch. A user is working on a single page for a while and the stale time runs out? Refetch. Again this is solved by setting the stale time to infinity and changing some of the defaults around refetching. I was just curious if anyone else had ran into something like this as well. Not sure if there might be another approach I should consider.
national-gold
national-gold2y ago
Having a cache is a tradeoff. You can define the stale as you like. And per default stale data is not refetched. Only on mount and window focus…
fair-rose
fair-rose2y ago
I doesn't really have anything to do with audit logs though. What do you do if a user just presses F5 in their browser a bunch of times, or if you actually have lots of users. If a resource doesn't need to be fetched as often, you have to specificy a staleTime. That's how the caching system works 🙂

Did you find this page helpful?