(key, {legacyFields = [], requestEpoch = cacheEpoch} = {})
| 59 | } |
| 60 | |
| 61 | export async function readCacheEntry(key, {legacyFields = [], requestEpoch = cacheEpoch} = {}) { |
| 62 | if (requestEpoch === cacheEpoch && memoryCache.has(key)) { |
| 63 | return memoryCache.get(key); |
| 64 | } |
| 65 | const pendingWrite = writeQueues.get(key); |
| 66 | if (pendingWrite) { |
| 67 | await pendingWrite.catch(() => { |
| 68 | }); |
| 69 | if (requestEpoch === cacheEpoch && memoryCache.has(key)) { |
| 70 | return memoryCache.get(key); |
| 71 | } |
| 72 | } |
| 73 | const versionBeforeRead = latestRequestVersions.get(key) ?? 0; |
| 74 | const entry = normalizeCacheEntry(await localforage.getItem(key), legacyFields); |
| 75 | if (requestEpoch !== cacheEpoch || (latestRequestVersions.get(key) ?? 0) !== versionBeforeRead) { |
| 76 | return memoryCache.get(key) ?? null; |
no test coverage detected