-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(axios): implement etag functionality #765
Conversation
pin axios to only allow minor patch upgrades, and pin the version of interceptor exactly. this is because there is a support table [here](https://axios-cache-interceptor.js.org/guide/getting-started) that lists the compat and we require at least 0.6.x for ETag support. in order to prevent versioning errors (0.8.4 of interceptor works wtih 0.25 of axios!!), we will pin the exact version of interceptor + patch version of axios
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Non-nit]
I think the stale time should be something that we should explicitly define in our application. If we monitor that our token usage is getting too high, it would be a lot easier for us to tweak this number to reduce the number of calls. Thoughts?
to clarify, you mean the max age of 60s? i think this number is explicitly given by github as a header for to let us know how long to cache a request before revalidation. i think the use case of allowing it in code to be able to control it is fair but we should add this as a follow up if required rather than having it as a first pass, because the default that github sends might already be enough! do take note that this refetch is only triggered on etag change - ie, past 60s, file is unchanged, github will return a 304 without consuming token usage wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to clarify, you mean the max age of 60s? i think this number is explicitly given by github as a header for to let us know how long to cache a request before revalidation. i think the use case of allowing it in code to be able to control it is fair but we should add this as a follow up if required rather than having it as a first pass, because the default that github sends might already be enough! do take note that this refetch is only triggered on etag change - ie, past 60s, file is unchanged, github will return a 304 without consuming token usage
makes sense to me, we can monitor if we actually want the ability to toggle the time taken for invalidation in the future then
* chore(axios): upgrade axios to 0.24 and add axios cache interceptor pin axios to only allow minor patch upgrades, and pin the version of interceptor exactly. this is because there is a support table [here](https://axios-cache-interceptor.js.org/guide/getting-started) that lists the compat and we require at least 0.6.x for ETag support. in order to prevent versioning errors (0.8.4 of interceptor works wtih 0.25 of axios!!), we will pin the exact version of interceptor + patch version of axios * feat(axiosinstance): add initialisation code * chore(package): lock versions * fix(axiosinstance): update config for cache interceptor
Problem
Currently, Isomer uses a huge amount of tokens due to not caching. This leads to scaling issue, where our github token limits are quickly reached and users are unable to access the CMS.
Closes IS-172
Solution
axios-cache-interceptor
to utilise ETags for cache. See here for info on etags.cache-control
header to control freshness (which is good). because github's header setsmax-age=60
, the package will internally use the old value for 60s.Tests
console.log
forremainingRequests
intorespHandler
forAxiosInstance.ts
, so that we know how much requests are remainingGET
request to thee2e-test-repo
's homepage (curl --request GET \ --url http://localhost:8081/v2/sites/e2e-test-repo/homepage
)New dependencies:
axios-cache-interceptor
: interceptor for axios to use etags. the current backing storage is in memory.Deploy notes
axios
got upgraded from0.21.x
to0.25.0
0.9.2
as a minimum foraxios-cache-interceptor
ETag
functionality only added in0.6
+ their import forobject-code
is an outdated one, which doesn't get fixed till0.9.2
.