Commit d2de675e authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

Modify a few logical errors

parent 36eeb6c1
...@@ -61,7 +61,6 @@ const cachedSave = (response, hashcode) => { ...@@ -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,10 +95,13 @@ export default function request(url, options = {}) { ...@@ -96,10 +95,13 @@ export default function request(url, options = {}) {
}; };
} }
} }
const expirys = options.expirys || 60;
// options.expirys !== false, return the cache,
if (options.expirys !== false) {
let cached = sessionStorage.getItem(hashcode); let cached = sessionStorage.getItem(hashcode);
let whenCached = sessionStorage.getItem(hashcode + ':timestamp'); let whenCached = sessionStorage.getItem(hashcode + ':timestamp');
const expirys = options.expirys || 60; if (cached !== null && whenCached !== null) {
if (cached !== null && whenCached !== null && expirys !== false) {
let age = (Date.now() - whenCached) / 1000; let age = (Date.now() - whenCached) / 1000;
if (age < expirys) { if (age < expirys) {
let response = new Response(new Blob([cached])); let response = new Response(new Blob([cached]));
...@@ -109,6 +111,7 @@ export default function request(url, options = {}) { ...@@ -109,6 +111,7 @@ export default function request(url, options = {}) {
sessionStorage.removeItem(hashcode + ':timestamp'); sessionStorage.removeItem(hashcode + ':timestamp');
} }
} }
}
return fetch(url, newOptions) return fetch(url, newOptions)
.then(checkStatus) .then(checkStatus)
.then(cachedSave) .then(cachedSave)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment