|
|
@ -61,7 +61,6 @@ const cachedSave = (response, hashcode) => { |
|
|
* @return {object} An object containing either "data" or "err" |
|
|
* @return {object} An object containing either "data" or "err" |
|
|
*/ |
|
|
*/ |
|
|
export default function request(url, options = {}) { |
|
|
export default function request(url, options = {}) { |
|
|
console.log(url); |
|
|
|
|
|
/** |
|
|
/** |
|
|
* Produce fingerprints based on url and parameters |
|
|
* Produce fingerprints based on url and parameters |
|
|
* Maybe url has the same parameters |
|
|
* Maybe url has the same parameters |
|
|
@ -96,17 +95,21 @@ export default function request(url, options = {}) { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
let cached = sessionStorage.getItem(hashcode); |
|
|
|
|
|
let whenCached = sessionStorage.getItem(hashcode + ':timestamp'); |
|
|
|
|
|
const expirys = options.expirys || 60; |
|
|
const expirys = options.expirys || 60; |
|
|
if (cached !== null && whenCached !== null && expirys !== false) { |
|
|
// options.expirys !== false, return the cache,
|
|
|
let age = (Date.now() - whenCached) / 1000; |
|
|
if (options.expirys !== false) { |
|
|
if (age < expirys) { |
|
|
let cached = sessionStorage.getItem(hashcode); |
|
|
let response = new Response(new Blob([cached])); |
|
|
let whenCached = sessionStorage.getItem(hashcode + ':timestamp'); |
|
|
return response.json(); |
|
|
if (cached !== null && whenCached !== null) { |
|
|
} else { |
|
|
let age = (Date.now() - whenCached) / 1000; |
|
|
sessionStorage.removeItem(hashcode); |
|
|
if (age < expirys) { |
|
|
sessionStorage.removeItem(hashcode + ':timestamp'); |
|
|
let response = new Response(new Blob([cached])); |
|
|
|
|
|
return response.json(); |
|
|
|
|
|
} else { |
|
|
|
|
|
sessionStorage.removeItem(hashcode); |
|
|
|
|
|
sessionStorage.removeItem(hashcode + ':timestamp'); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return fetch(url, newOptions) |
|
|
return fetch(url, newOptions) |
|
|
|