-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pathUtils | fix memory leak #418
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class LRUCache { | ||
/** | ||
* @param {number} maxSize maxSize | ||
*/ | ||
constructor(maxSize) { | ||
this._maxSize = maxSize; | ||
/** @type {string[]} */ | ||
this._doublyQueue = []; | ||
this._cacheMap = new Map(); | ||
} | ||
|
||
/** | ||
* @param {string} item item | ||
*/ | ||
get(item) { | ||
if (this._cacheMap.has(item)) { | ||
const itemData = this._doublyQueue.splice( | ||
this._doublyQueue.indexOf(item), | ||
1 | ||
); | ||
this._doublyQueue.unshift(item); | ||
|
||
if (itemData.length > 0) { | ||
this._cacheMap.set(item, itemData[0]); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {any} item item | ||
* @param {any} itemData itemData | ||
*/ | ||
set(item, itemData) { | ||
if (this._doublyQueue.length === this._maxSize) { | ||
const last = this._doublyQueue[this._doublyQueue.length - 1]; | ||
this._doublyQueue.pop(); | ||
this._cacheMap.delete(last); | ||
} | ||
|
||
this._doublyQueue.unshift(item); | ||
this._cacheMap.set(item, itemData); | ||
} | ||
} | ||
|
||
module.exports = LRUCache; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
}, | ||
"dependencies": { | ||
"graceful-fs": "^4.2.4", | ||
"lru-cache": "^10.2.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this big package here, you can rewrite this package and put it inside project, because we use only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll implement it and update |
||
"tapable": "^2.2.0" | ||
}, | ||
"license": "MIT", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use your implementation here and remove this package from here