Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

AllllenLuo
Copy link

Change in Cache Mechanism:

  • Update cache in both client and server side to be size-based instead of entry-based

@domoritz domoritz changed the title Update the lru cache feat: switch cache to be memory size based Nov 6, 2024

for (const [key, value] of cache) {
const { last } = value;
while (currSize > max) {
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no logs

Comment on lines +67 to +71
if (cache.has(key)) {
currSize -= cache.get(key).size;
}
cache.set(key, setValue);
currSize += setValue.size;
Copy link
Member

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 {
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants