[Part 6] Add a DebouncedCache utility for frontend #443
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before you begin
Debouncing and Caching
Today, there is an annoying implementation behaviour of debouncing and caching for server-side completions. We debounce user input with a 300ms threshold, then send a server-side completions request and cache its result. However, if the user changes the input and then returns back to the cached input, the user still needs to wait for a 300ms debounce threshold before the cached results are displayed.
I fixed this behaviour and also moved this logic into a generic
DebouncedCache
class. It also manages anAbortController/AbortSignal
, so that it can cancel the processing after an HTTP request was invoked if the user typed some more characters in the middle of that. So this change eliminates another race condition, where previously the user could receive stale sever-side completion results while they were typing. It isn't a critical bug though, but still nice to see it fixed.