Skip to content

Commit

Permalink
good version of LRU
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvestre Gug committed Jan 26, 2023
1 parent b541e5c commit 2c461c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/pools.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import LRU from "lru-cache";
import * as Sentry from "@sentry/node";

const ttl = 1000 * 60 * 10; // 10m
const maxAge = 1000 * 60 * 10; // 10m

export default class Pools {
constructor(createPool) {
this.createPool = createPool;
this.cache = new LRU({
max: 100,
ttl,
maxAge,
updateAgeOnGet: true,
dispose(_key, pool) {
pool.end();
Expand All @@ -17,8 +17,8 @@ export default class Pools {

let loop;
(loop = () => {
this.cache.purgeStale();
this.timeout = setTimeout(loop, ttl / 2);
this.cache.prune();
this.timeout = setTimeout(loop, maxAge / 2);
})();
}

Expand All @@ -45,7 +45,7 @@ export default class Pools {
}

del(credentials) {
this.cache.delete(JSON.stringify(credentials));
this.cache.del(JSON.stringify(credentials));
}

end() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@sentry/node": "^7.33.0",
"JSONStream": "^1.3.5",
"ajv": "^8.11.0",
"lru-cache": "^7.14.1",
"lru-cache": "^6.0.0",
"micro": "^9.3.4",
"mssql": "^9.0.1",
"mysql2": "^3.0.1",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,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-cache@^7.14.1:
version "7.14.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
Expand Down Expand Up @@ -5756,6 +5763,11 @@ yallist@^3.0.2:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

[email protected]:
version "20.2.4"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"
Expand Down

0 comments on commit 2c461c0

Please sign in to comment.