feat: add a simple in-memory cache for suborg/repo config fetches #817
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.
Fixes #816
This PR adds a simple in-memory cache in the
loadYaml
function, that stores the response + etag of calls to thegetContent
call. Then, future calls are made with theIf-None-Match
header set to that etag, so that we can optimistically just return from the cache instead and save ourselves the api call. In our instance of safe settings, this ends up saving about 96% of our api calls for our app. (We've made 3.4M api calls in the last week, of which 3.248M were cached - about 95.5%)Because safe settings attempts to load all of the repo configs & suborg configs every time a sync is done, that api call usage tends to grow explosively on large orgs. We run this in an org with around 8500 repos in it, and because we have 140-ish suborgs, that ends up being 140 suborg calls against our api limit every time a setting is changed!
With this change, we store the response of each of those calls in memory, and only make an api call if github knows the file contents have changed.
This is a VERY simple cache, so it has some limitations: