Skip to content

Commit

Permalink
fix: 清除过期了的缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
qiu8310 committed May 10, 2016
1 parent a30dc99 commit 83b7d56
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
21 changes: 16 additions & 5 deletions dist/elegant-api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/elegant-api.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/elegant-api.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/ElegantApi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ module.exports = class ElegantApi {


_getCache(route) {
let {cacheMap} = this.globals;
let {cacheMap, cacheStack} = this.globals;
let {name, http} = route, key;

let exists = false, value = null, data;
Expand All @@ -219,6 +219,15 @@ module.exports = class ElegantApi {
let expire = data.expire;
if (expire !== 0 && expire < (+new Date)) {
exists = false;

// 删除缓存中的数据
delete cacheMap[key];
for (let i = 0; i < cacheStack.length; i++) {
if (cacheStack[i][0] === name && cacheStack[i][1] === key) {
cacheStack.splice(i, 1);
break;
}
}
} else {
value = data.value;
}
Expand Down

0 comments on commit 83b7d56

Please sign in to comment.