* Add item to cache
(url, response)
| 66 | * Add item to cache |
| 67 | */ |
| 68 | async set(url, response) { |
| 69 | const key = this.getCacheKey(url); |
| 70 | |
| 71 | // Clone the response to read it |
| 72 | const responseClone = response.clone(); |
| 73 | |
| 74 | // Read the response body as blob (more reliable than storing Response objects) |
| 75 | const blob = await responseClone.blob(); |
| 76 | |
| 77 | // Check actual blob size |
| 78 | const fileSize = blob.size; |
| 79 | |
| 80 | // Don't cache if too large |
| 81 | if (fileSize > this.maxFileSize) { |
| 82 | log('[FileCache] File too large to cache:', key, `(${fileSize} bytes)`); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | // Store blob and metadata separately to avoid Response stream issues |
| 87 | const entry = { |
| 88 | blob: blob, |
| 89 | status: response.status, |
| 90 | statusText: response.statusText, |
| 91 | headers: new Headers(response.headers), // Clone headers |
| 92 | timestamp: Date.now(), |
| 93 | size: fileSize |
| 94 | }; |
| 95 | |
| 96 | this.cache.set(key, entry); |
| 97 | log('[FileCache] Cached:', key, `(${fileSize} bytes)`); |
| 98 | |
| 99 | // Enforce size limit |
| 100 | this.enforceSizeLimit(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Remove oldest entries if cache is full (LRU) |
no test coverage detected