提交 d2de675e 编写于 作者: 陈帅

Modify a few logical errors

上级 36eeb6c1
......@@ -61,7 +61,6 @@ const cachedSave = (response, hashcode) => {
* @return {object} An object containing either "data" or "err"
*/
export default function request(url, options = {}) {
console.log(url);
/**
* Produce fingerprints based on url and 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;
if (cached !== null && whenCached !== null && expirys !== false) {
let age = (Date.now() - whenCached) / 1000;
if (age < expirys) {
let response = new Response(new Blob([cached]));
return response.json();
} else {
sessionStorage.removeItem(hashcode);
sessionStorage.removeItem(hashcode + ':timestamp');
// options.expirys !== false, return the cache,
if (options.expirys !== false) {
let cached = sessionStorage.getItem(hashcode);
let whenCached = sessionStorage.getItem(hashcode + ':timestamp');
if (cached !== null && whenCached !== null) {
let age = (Date.now() - whenCached) / 1000;
if (age < expirys) {
let response = new Response(new Blob([cached]));
return response.json();
} else {
sessionStorage.removeItem(hashcode);
sessionStorage.removeItem(hashcode + ':timestamp');
}
}
}
return fetch(url, newOptions)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册