MCPcopy Create free account
hub / github.com/OpenSIST/OpenSIST.github.io / beginCacheRequests

Function beginCacheRequests

src/Data/CacheStore.js:138–175  ·  view source on GitHub ↗
(keys, priority = FOREGROUND_PRIORITY, requestEpoch = cacheEpoch)

Source from the content-addressed store, hash-verified

136}
137
138export 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
177export async function loadCachedValue({
178 forceRefresh = false,

Callers 3

getMetadataBatchFunction · 0.90
getProgramDescsFunction · 0.90
loadCachedValueFunction · 0.85

Calls 1

nextRequestVersionFunction · 0.85

Tested by

no test coverage detected