Skip to content

Commit

Permalink
Fix the bug of stucking after reaching cache limit
Browse files Browse the repository at this point in the history
  • Loading branch information
AllllenLuo committed Nov 19, 2024
1 parent 31ad0e5 commit ced98de
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/util/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export function lruCache({
// remove if time since last access exceeds ttl
if (expire > last) {
cache.delete(key);
currSize -= lruSize;
currSize -= size;
}
}

// remove lru entry
if (cache.has(lruKey)) {
currSize -= cache.get(lruKey).size;
currSize -= lruSize;
cache.delete(lruKey);
}
}
Expand All @@ -51,6 +51,7 @@ export function lruCache({
return {
get(key) {
const entry = cache.get(key);
console.log("Size", currSize, cache.size)
if (entry) {
entry.last = performance.now();
return entry.value;
Expand All @@ -62,6 +63,10 @@ export function lruCache({
size: new Blob([value]).size,
value
};

if (cache.has(key)) {
currSize -= cache.get(key).size;
}
cache.set(key, setValue);
currSize += setValue.size;

Expand Down

0 comments on commit ced98de

Please sign in to comment.