Skip to content

Commit 2c461c0

Browse files
author
Sylvestre Gug
committed
good version of LRU
1 parent b541e5c commit 2c461c0

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

lib/pools.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import LRU from "lru-cache";
22
import * as Sentry from "@sentry/node";
33

4-
const ttl = 1000 * 60 * 10; // 10m
4+
const maxAge = 1000 * 60 * 10; // 10m
55

66
export default class Pools {
77
constructor(createPool) {
88
this.createPool = createPool;
99
this.cache = new LRU({
1010
max: 100,
11-
ttl,
11+
maxAge,
1212
updateAgeOnGet: true,
1313
dispose(_key, pool) {
1414
pool.end();
@@ -17,8 +17,8 @@ export default class Pools {
1717

1818
let loop;
1919
(loop = () => {
20-
this.cache.purgeStale();
21-
this.timeout = setTimeout(loop, ttl / 2);
20+
this.cache.prune();
21+
this.timeout = setTimeout(loop, maxAge / 2);
2222
})();
2323
}
2424

@@ -45,7 +45,7 @@ export default class Pools {
4545
}
4646

4747
del(credentials) {
48-
this.cache.delete(JSON.stringify(credentials));
48+
this.cache.del(JSON.stringify(credentials));
4949
}
5050

5151
end() {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@sentry/node": "^7.33.0",
2323
"JSONStream": "^1.3.5",
2424
"ajv": "^8.11.0",
25-
"lru-cache": "^7.14.1",
25+
"lru-cache": "^6.0.0",
2626
"micro": "^9.3.4",
2727
"mssql": "^9.0.1",
2828
"mysql2": "^3.0.1",

yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,13 @@ lru-cache@^5.1.1:
36193619
dependencies:
36203620
yallist "^3.0.2"
36213621

3622+
lru-cache@^6.0.0:
3623+
version "6.0.0"
3624+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
3625+
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
3626+
dependencies:
3627+
yallist "^4.0.0"
3628+
36223629
lru-cache@^7.14.1:
36233630
version "7.14.1"
36243631
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
@@ -5756,6 +5763,11 @@ yallist@^3.0.2:
57565763
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
57575764
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==
57585765

5766+
yallist@^4.0.0:
5767+
version "4.0.0"
5768+
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
5769+
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
5770+
57595771
57605772
version "20.2.4"
57615773
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"

0 commit comments

Comments
 (0)