MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / cachedProxyResponse

Function cachedProxyResponse

scripts/studio-provider-bridge.mjs:493–521  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

491}
492
493async function cachedProxyResponse(request) {
494 const cacheKey = cacheKeyForRequest(request);
495 if (!cacheKey || simulatorListCacheTtlMs <= 0) {
496 return proxyLocalRequest(request);
497 }
498
499 const cached = responseCache.get(cacheKey);
500 if (cached && Date.now() - cached.updatedAt <= simulatorListCacheTtlMs) {
501 return cached.payload;
502 }
503
504 const pending = inFlightCache.get(cacheKey);
505 if (pending) {
506 return pending;
507 }
508
509 const pendingRequest = proxyLocalRequest(request)
510 .then((payload) => {
511 if (payload.responseStatus >= 200 && payload.responseStatus < 300) {
512 responseCache.set(cacheKey, { payload, updatedAt: Date.now() });
513 }
514 return payload;
515 })
516 .finally(() => {
517 inFlightCache.delete(cacheKey);
518 });
519 inFlightCache.set(cacheKey, pendingRequest);
520 return pendingRequest;
521}
522
523function cacheKeyForRequest(request) {
524 if (request.method !== "GET") {

Callers 1

handleRequestFunction · 0.85

Calls 5

cacheKeyForRequestFunction · 0.85
setMethod · 0.80
proxyLocalRequestFunction · 0.70
getMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected