-
Notifications
You must be signed in to change notification settings - Fork 686
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
[feature]: Implement graphQL query caching at Service Worker Level. #1767
Comments
Additional discovery required for application of Apollo functionality here, need to determine need to have this caching at the SW vs Apollo. @revanth0212 @zetlen |
Here's the Apollo documentation (and https://www.apollographql.com/docs/react/caching/cache-interaction/). Emphasis mine:
If we don't want to use the cached version of a query, we can just use a different fetchPolicy for that query. |
There are queries in Magento which should not be cached, like isEmailAvailable query when creating customer account. So Apollo to SW, we can use the fetch policy of apollo. |
I am not sure of the Apollo policy. Definitely something to look into. Meanwhile, it is no possible to cache POST calls in the browser cache storage. There is an open issue in SW Spec repo to enable this w3c/ServiceWorker#693. Although this is an open issue, I am not sure if this will be implemented any time soon, since this issue was open since 2015. There is a workaround for caching POST calls but the work involved is not justifiable of the performance benefit we will be getting back. Hence removing this issue from the Performance Milestone for now. I will check back in the future. It can be a good first issue as well if someone wants to work on it. |
This should stay open because we don't strictly need to use CacheStorage to cache things in the ServiceWorker. It is the simplest approach, and ServiceWorker is designed for it, so @revanth0212 is right that we should use CacheStorage as soon as we can. However, ServiceWorkers can still intercept fetches with non-GET HTTP methods. We can store responses in an indexedDB and build Response objects manually to respond from cache instead of keeping Responses in CacheStorage directly. It's something to research. |
@magento export issue to JIRA project PWA as Story |
✅ Jira issue https://jira.corp.magento.com/browse/PWA-1756 is successfully created for this GitHub issue. |
We can do this if the Query calls are GET-based instead of POST. Since now all the GQL queries in Venia are GET, we can add corresponding rules in the SW to cache for a certain time period. |
Is your feature request related to a problem? Please describe.
Related to #1673
Describe the solution you'd like
As of today, we are not caching graphQL query results. This will be useful when it comes to offline experience and also quick instant responses when it comes to data that might not change often like
storeConfig
.Please let us know what packages this feature is in regards to:
venia-concept
venia-ui
pwa-buildpack
peregrine
pwa-devdocs
upward-js
upward-spec
The text was updated successfully, but these errors were encountered: