Skip to content
Snippets Groups Projects
Commit 524ed90e authored by Alexander Rose's avatar Alexander Rose
Browse files

lru cache set returns removed entry

parent 7abba750
No related branches found
No related tags found
No related merge requests found
......@@ -43,11 +43,14 @@ namespace LRUCache {
return void 0;
}
export function set<T>(cache: LRUCache<T>, key: string, data: T): T {
export function set<T>(cache: LRUCache<T>, key: string, data: T): T | undefined {
let removed: T | undefined = undefined;
if (cache.entries.count >= cache.capacity) {
cache.entries.remove(cache.entries.first!);
const first = cache.entries.first!;
removed = first.value.data;
cache.entries.remove(first);
}
cache.entries.addLast(entry(key, data));
return data;
return removed;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment