Skip to content
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

When Cache API is not available, dont clone response for cachePut #8416

Open
asheemmamoowala opened this issue Jul 1, 2019 · 2 comments
Open

Comments

@asheemmamoowala
Copy link
Contributor

The cacheGet method calls back to validateOrFetch with a null error if window.caches is not available. From what I can tell, this could happen when the Cache API is not available at all or if a page is served over http and the Cache API is not usable.

export function cacheGet(request: Request, callback: (error: ?any, response: ?Response, fresh: ?boolean) => void) {
if (!window.caches) return callback(null);
window.caches.open(CACHE_NAME)
.catch(callback)
.then(cache => {
cache.match(request, { ignoreSearch: true })
.catch(callback)
.then(response => {

In this case validateOrFetch still calls clones the response and attempts to place it in the cache.

window.fetch(request).then(response => {
if (response.ok) {
const cacheableResponse = cacheIgnoringSearch ? response.clone() : null;
return finishRequest(response, cacheableResponse, requestTime);

If it is known that window.caches is no available or usable, there is not need to clone the response or to load its contents:

const finishRequest = (response, cacheableResponse, requestTime) => {
(
requestParameters.type === 'arrayBuffer' ? response.arrayBuffer() :
requestParameters.type === 'json' ? response.json() :
response.text()
).then(result => {
if (cacheableResponse && requestTime) {
// The response needs to be inserted into the cache after it has completely loaded.

@ahk
Copy link
Contributor

ahk commented Jul 8, 2019

Didn't a fix for this get merged into our most recent release as a late patch, or do I misunderstand the extent of the bug?

@asheemmamoowala
Copy link
Contributor Author

@ahk This was not addressed. I can still reproduce this in the latest master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants