-
Notifications
You must be signed in to change notification settings - Fork 17
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(javascript): use responses and requests cache #281
Conversation
✅ Deploy Preview for api-clients-automation canceled.
|
✗ The generated branch has been deleted. If the PR has been merged, you can check the generated code on the |
8d47222
to
46cbe6a
Compare
request: Request, | ||
requestOptions: RequestOptions | ||
): Promise<TResponse> { | ||
if (request.method !== 'GET') { |
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.
Is it the same condition as what we already have in v4?
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.
Exactly, except that the v4 have read
and write
request, here we have a single one and early exit
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.
I cannot find anything about non- GET
methods. We use lots of POST methods, and we won't be able to use cache for POST method?
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.
Responses to POST Request are not cacheable
according to the HTTP spec.
Maybe the request is
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.
Yep, basically you should only cache GET
requests.
This is reflected in v4 by splitting the request
method in two: read
and write
- Anything different than
GET
will use https://github.com/algolia/algoliasearch-client-javascript/blob/master/packages/transporter/src/createTransporter.ts#L135-L149 - While
GET
will use https://github.com/algolia/algoliasearch-client-javascript/blob/master/packages/transporter/src/createTransporter.ts#L37-L40
You can search for MethodEnum.Get
in the codebase, or Post
, etc.
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.
Oh, that's what it meant by read and write there. yeah, let's go with this for the compatibility.
However, now that we're already using POST very heavily to get data, not allowing cache for POST was probably a mistake in v4.
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.
I believe it was more a matter of following good practices, this is (or was?) recommended to invalidate cache for write requests
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.
I wonder if on the engine side there's a reason to use post
for search
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.
IIRC, with GET method, there's a small limitation on url query parameters, where we tend to send a huge query string (think about InstantSearch), so we sort of had to use POST, which is not intended for the purpose, though.
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.
ah that make sense
🧭 What and Why
🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-176
Changes included:
Follow up of #274
responses
andrequests
cache increateTransporter
transporter
folderNext step
Import transporter tests from the existing suite
🧪 Test
CI :D