Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit e72090d

Browse files
committed
0.11
1 parent 70aa0df commit e72090d

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

cache.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ class LightCache {
2626
}
2727
return memory.value;
2828
}
29-
getOrSet(key, sync, expiration) {
30-
const cache = this.getCache(key);
31-
return cache === undefined ? this.setCache(key, sync(), expiration) : cache;
32-
}
33-
async asyncGetOrSet(key, async, expiration) {
34-
const cache = this.getCache(key);
35-
return cache === undefined ? this.setCache(key, await async(), expiration) : cache;
36-
}
3729
}
3830

3931
class ApiCache extends LightCache {
@@ -43,7 +35,6 @@ class ApiCache extends LightCache {
4335
this.expiration = conf.expiration;
4436
}
4537
async syncAxios(url) {
46-
logger.debug("Request GitHub API address:", url);
4738
return (await axios.get(url, {
4839
headers: {
4940
Accept: "application/json",
@@ -54,11 +45,16 @@ class ApiCache extends LightCache {
5445

5546
async requestWithCache(url) {
5647
// 类似于 Service Worker 缓存机制
57-
return this.asyncGetOrSet(
58-
url,
59-
async () => (await this.syncAxios(url)),
60-
this.expiration,
61-
);
48+
const cache = this.getCache(url);
49+
if (cache === undefined) {
50+
logger.info("Request GitHub API address: ", url);
51+
const response = await this.syncAxios(url);
52+
this.setCache(url, response, this.expiration);
53+
return response;
54+
} else {
55+
logger.debug("Cached GitHub API address: ", url);
56+
return cache;
57+
}
6258
}
6359
}
6460

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
expiration: 3600, // expiration second
44
requires: ["*"], // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
55
port: 8000, // server port
6-
host : "localhost",
6+
host: "localhost",
77
}

0 commit comments

Comments
 (0)