(keys, priority = FOREGROUND_PRIORITY, requestEpoch = cacheEpoch)
| 136 | await localforage.clear(); |
| 137 | if (theme) { |
| 138 | await localforage.setItem("theme", theme); |
| 139 | } |
| 140 | if (typeof window !== "undefined") { |
| 141 | window.dispatchEvent(new Event(CACHE_CLEARED_EVENT)); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | export function getCacheEpoch() { |
| 146 | return cacheEpoch; |
| 147 | } |
| 148 | |
| 149 | export function beginCacheRequests(keys, priority = FOREGROUND_PRIORITY, requestEpoch = cacheEpoch) { |
| 150 | if (requestEpoch !== cacheEpoch) { |
| 151 | return { |
| 152 | keys: [], |
| 153 | epoch: requestEpoch, |
| 154 | versionFor: () => undefined, |
| 155 | release() { |
| 156 | }, |
| 157 | }; |
| 158 | } |
| 159 | const isBackground = priority === BACKGROUND_PRIORITY; |
| 160 | const requestKeys = isBackground |
| 161 | ? keys.filter((key) => !foregroundRequests.has(key)) |
| 162 | : keys; |
| 163 | const versions = new Map(requestKeys.map((key) => [key, nextRequestVersion(key)])); |
| 164 | if (!isBackground) { |
| 165 | requestKeys.forEach((key) => foregroundRequests.set(key, (foregroundRequests.get(key) ?? 0) + 1)); |
| 166 | } |
| 167 | |
| 168 | return { |
| 169 | keys: requestKeys, |
| 170 | epoch: requestEpoch, |
| 171 | versionFor: (key) => versions.get(key), |
| 172 | release() { |
| 173 | if (isBackground) { |
| 174 | return; |
| 175 | } |
| 176 | requestKeys.forEach((key) => { |
| 177 | const remaining = (foregroundRequests.get(key) ?? 1) - 1; |
| 178 | if (remaining > 0) { |
no test coverage detected