Skip to content

Commit

Permalink
chore: bump lru-cache from 6.0.0 to 7.7.1 (DIYgod#9339)
Browse files Browse the repository at this point in the history
* feat(core): lru-cache v7

* chore: bump lru-cache to 7.7.1

* feat: configurable max
  • Loading branch information
TonyRL authored Mar 18, 2022
1 parent ae90428 commit 2ed9fd5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/en/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ RSSHub supports two caching methods: memory and redis

`REDIS_URL`: Redis target address (invalid when `CACHE_TYPE` is set to memory), default to `redis://localhost:6379/`

`MEMORY_MAX`: maximum number of cached items (invalid when `CACHE_TYPE` is set to redis), default to `256`

### Proxy Configurations

Partial routes have a strict anti-crawler policy, and can be configured to use proxy.
Expand Down
2 changes: 2 additions & 0 deletions docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式

`REDIS_URL`: Redis 连接地址(redis 缓存类型时有效),默认为 `redis://localhost:6379/`

`MEMORY_MAX`: 最大缓存数量(memory 缓存类型时有效),默认 `256`

### 代理配置

部分路由反爬严格,可以配置使用代理抓取。
Expand Down
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const calculateValue = () => {
routeExpire: parseInt(envs.CACHE_EXPIRE) || 5 * 60, // 路由缓存时间,单位为秒
contentExpire: parseInt(envs.CACHE_CONTENT_EXPIRE) || 1 * 60 * 60, // 不变内容缓存时间,单位为秒
},
memory: {
max: envs.MEMORY_MAX || Math.pow(2, 8), // The maximum number of items that remain in the cache. This must be a positive finite intger.
// https://github.com/isaacs/node-lru-cache#options
},
redis: {
url: envs.REDIS_URL || 'redis://localhost:6379/',
},
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (config.cache.type === 'redis') {
value = JSON.stringify(value);
}
if (key) {
return pageCache.set(key, value, maxAge * 1000);
return pageCache.set(key, value, { ttl: maxAge * 1000 });
}
};
} else {
Expand Down
10 changes: 5 additions & 5 deletions lib/middleware/cache/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const config = require('@/config').value;
const status = { available: false };

const pageCache = new Lru({
maxAge: config.cache.routeExpire * 1000,
max: Infinity,
ttl: config.cache.routeExpire * 1000,
max: config.memory.max,
});

const routeCache = new Lru({
maxAge: config.cache.routeExpire * 1000,
max: Infinity,
ttl: config.cache.routeExpire * 1000,
max: config.memory.max,
updateAgeOnGet: true,
});

Expand All @@ -34,7 +34,7 @@ module.exports = {
value = JSON.stringify(value);
}
if (key && status.available) {
return (refresh ? routeCache : pageCache).set(key, value, maxAge * 1000);
return (refresh ? routeCache : pageCache).set(key, value, { ttl: maxAge * 1000 });
}
},
clients: { pageCache, routeCache },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"koa-basic-auth": "4.0.0",
"koa-favicon": "2.1.0",
"koa-mount": "4.0.0",
"lru-cache": "6.0.0",
"lru-cache": "7.7.1",
"lz-string": "1.4.4",
"mailparser": "3.4.0",
"markdown-it": "12.3.2",
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9005,12 +9005,10 @@ lowercase-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479"
integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==

[email protected], lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
dependencies:
yallist "^4.0.0"
[email protected]:
version "7.7.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.7.1.tgz#03d2846b1ad2dcc7931a9340b8711d9798fcb0c6"
integrity sha512-cRffBiTW8s73eH4aTXqBcTLU0xQnwGV3/imttRHGWCrbergmnK4D6JXQd8qin5z43HnDwRI+o7mVW0LEB+tpAw==

lru-cache@^4.0.1, lru-cache@^4.1.2:
version "4.1.5"
Expand All @@ -9027,6 +9025,13 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
dependencies:
yallist "^4.0.0"

lru_map@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
Expand Down

0 comments on commit 2ed9fd5

Please sign in to comment.