* Get item from cache
(url)
| 36 | * Get item from cache |
| 37 | */ |
| 38 | async get(url) { |
| 39 | const key = this.getCacheKey(url); |
| 40 | const entry = this.cache.get(key); |
| 41 | |
| 42 | if (!entry) { |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | if (!this.isValid(entry)) { |
| 47 | log('[FileCache] Cache expired:', key); |
| 48 | this.cache.delete(key); |
| 49 | return null; |
| 50 | } |
| 51 | |
| 52 | // Move to end (LRU) |
| 53 | this.cache.delete(key); |
| 54 | this.cache.set(key, entry); |
| 55 | |
| 56 | // Create a new Response from the stored blob to avoid body stream issues |
| 57 | const blob = entry.blob; |
| 58 | return new Response(blob, { |
| 59 | status: entry.status, |
| 60 | statusText: entry.statusText, |
| 61 | headers: entry.headers |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Add item to cache |