Hi all,
During the new host details page implementations (host statuses specifically), I was observing that we don’t have a client-side caching mechanism for API requests.
This lack might cause redundant API calls (for example, when we switch between tabs), which means fetching the same data over and over again.
This is the main reason why I’ve created this addition to our API middleware which adds a client-side caching mechanism.
How it works
This addition adds a new option - expiresIn
, this adds a timestamp for the corresponding API calls.
If an API call owns the expiresIn
value, the client-side will prevent from dispatching another API call with the same key in the given window.
Example
dispatch(
get({
key: SPECIAL_KEY,
url,
expiresIn: 10000, // an API call with the same key won't be dispatched unless at least 10 seconds been passed
})
);
I’d like to hear more opinions about this approach or any other suggestion.
Thanks!