Skip to content

Commit 894feaa

Browse files
committed
🎉 support set MAX_CACHE_ITEMS now
1 parent 3623198 commit 894feaa

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ CSDN:`https://stats.justsong.cn/api/csdn?id=vczh`
102102
1. `BILIBILI_SESSDATA`:B 站的 `SESSDATA` Cookie,用以抓取 B 站数据,注意这个 Cookie 半年过期一次,届时需要重新设置 & 部署。
103103
2. `GITHUB_TOKEN`:GitHub Token,无任何权限的即可,用于抓取 GitHub 数据。
104104
3. `CACHE_TIME`:缓存时间,包括服务端缓存和客户端缓存,单位为秒,默认 `6000`,即 100 分钟。
105-
4. `PORT`:服务端口号,默认 `3000`
105+
4. `MAX_CACHE_ITEMS`:最大缓存数量,默认 `1024`,缓存超出后将采取 LRU 策略进行淘汰。
106+
5. `PORT`:服务端口号,默认 `3000`
106107

107108
### 部署到 Vercel
108109

common/cache.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// https://github.com/isaacs/node-lru-cache
22
const LRU = require('lru-cache');
33

4-
const cacheTime = process.env.CACHE_TIME || 100 * 60; // 100 min
4+
const cacheTime = process.env.CACHE_TIME || 100 * 60; // 100 min
5+
const maxCacheItems = process.env.MAX_CACHE_ITEMS || 1024;
56

67
const options = {
7-
max: 1000,
8+
max: maxCacheItems,
89
// how long to live in ms
910
ttl: cacheTime * 1000,
1011
// return stale items before removing from cache?
1112
allowStale: true,
1213
updateAgeOnGet: false,
13-
updateAgeOnHas: false
14+
updateAgeOnHas: false,
1415
};
1516

1617
const cache = new LRU(options);
1718

1819
module.exports = {
1920
cache,
20-
cacheTime
21-
};
21+
cacheTime,
22+
};

0 commit comments

Comments
 (0)