-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: switch cache to be memory size based #9
base: main
Are you sure you want to change the base?
Conversation
…instead of entry-based
|
||
for (const [key, value] of cache) { | ||
const { last } = value; | ||
while (currSize > max) { |
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.
This is basically an if statement and would means we don't go into the loop if the size is not exceeded but we have expired items.
} | ||
|
||
return { | ||
get(key) { | ||
const entry = cache.get(key); | ||
console.log("Size", currSize, cache.size) |
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.
no logs
if (cache.has(key)) { | ||
currSize -= cache.get(key).size; | ||
} | ||
cache.set(key, setValue); | ||
currSize += setValue.size; |
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.
It's easier to not even set when the item already exists.
@@ -22,14 +22,15 @@ class CacheEntry { | |||
|
|||
export class Cache { |
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.
Can we remove this and use (or at least extend) the implementation from core utils?
Change in Cache Mechanism: