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