Skip to content

Commit a3ec206

Browse files
dlongleydavidlehn
authored andcommitted
Add max cache size for initial context cache.
1 parent 03b252a commit a3ec206

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/context.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
const MAX_CONTEXT_URLS = 10;
2525

2626
const INITIAL_CONTEXT_CACHE = new Map();
27+
const INITIAL_CONTEXT_CACHE_MAX_SIZE = 10000;
2728

2829
const api = {};
2930
module.exports = api;
@@ -646,6 +647,9 @@ api.getInitialContext = (options) => {
646647
getInverse: _createInverseContext,
647648
clone: _cloneActiveContext
648649
};
650+
if(INITIAL_CONTEXT_CACHE.size === INITIAL_CONTEXT_CACHE_MAX_SIZE) {
651+
INITIAL_CONTEXT_CACHE.delete(INITIAL_CONTEXT_CACHE.keys().next().value);
652+
}
649653
INITIAL_CONTEXT_CACHE.set(key, initialContext);
650654
return initialContext;
651655

0 commit comments

Comments
 (0)