1 parent b51eca1 commit 48d05edCopy full SHA for 48d05ed
1 file changed
frontend/src/stores/papers.ts
@@ -7,10 +7,19 @@ export const usePaperStore = defineStore('paper', () => {
7
8
async function getPdf(paperId: number): Promise<Blob> {
9
const cached = pdfCache.get(paperId);
10
- if (cached) return cached;
+ if (cached) {
11
+ // refresh LRU position by reinserting the cached entry
12
+ pdfCache.delete(paperId);
13
+ pdfCache.set(paperId, cached);
14
+ return cached;
15
+ }
16
- if (pdfCache.size > 40) {
- pdfCache.clear();
17
+ // enforce a max cache size using a simple LRU eviction strategy
18
+ if (pdfCache.size >= 40) {
19
+ const oldestKey = pdfCache.keys().next().value as number | undefined;
20
+ if (oldestKey !== undefined) {
21
+ pdfCache.delete(oldestKey);
22
23
}
24
25
const blob = await fetchPaperPdf(paperId);
0 commit comments