Cache custom-query JSON responses to avoid API rate limits - #40
Merged
0xSpuddy merged 3 commits intoJul 9, 2026
Merged
Conversation
…void price-source API rate limits
…od (keep x/sync direct at v0.19.0)
0xSpuddy
approved these changes
Jul 7, 2026
0xSpuddy
left a comment
Contributor
There was a problem hiding this comment.
looks good to me. Offered a small waiting behavior fix, but should work well enough as is.
| return nil, err | ||
| } | ||
| return v.([]byte), nil | ||
| } |
Contributor
There was a problem hiding this comment.
Should we use sharedCache.group.DoChan instead of sharedCache.group.Do to avoid callers waiting longer than they need to when the leader's http call times out? (the code works as is, this is a small waiting behavior fix)
ch := sharedCache.group.DoChan(key, func() (interface{}, error) {
// Re-check: a concurrent leader may have just populated the cache.
if body, ok := sharedCache.get(key); ok {
return body, nil
}
body, err := r.fetchWithRetry(ctx)
if err != nil {
return nil, err
}
sharedCache.set(key, body)
return body, nil
})
select {
case res := <-ch:
if res.Err != nil {
return nil, res.Err
}
return res.Val.([]byte), nil
case <-ctx.Done():
return nil, ctx.Err()
}
}
0xSpuddy
approved these changes
Jul 9, 2026
0xSpuddy
left a comment
Contributor
There was a problem hiding this comment.
Looks cool, and it will be interesting to see if calls go down after the changes. Will merge into main now and then test it on palmito for a day before making a new release with all these pull requests in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.