MCPcopy
hub / github.com/promptfoo/promptfoo / getFetchCacheKey

Function getFetchCacheKey

src/cache.ts:515–544  ·  view source on GitHub ↗
(
  url: RequestInfo,
  options: RequestInit,
  method: string,
  format: 'json' | 'text',
  repeatIndex?: number,
)

Source from the content-addressed store, hash-verified

513}
514
515function getFetchCacheKey(
516 url: RequestInfo,
517 options: RequestInit,
518 method: string,
519 format: 'json' | 'text',
520 repeatIndex?: number,
521) {
522 const bodyForCacheKey = getBodyForFetchCacheKey(
523 options.body ?? (url instanceof Request ? url.body : undefined),
524 );
525 if (!bodyForCacheKey.cacheable) {
526 return null;
527 }
528
529 const optionsForCacheKey = getOptionsForFetchCacheKey(options, bodyForCacheKey.identity);
530 if (!optionsForCacheKey.cacheable) {
531 return null;
532 }
533
534 const repeatSuffix = shouldApplyRepeatCacheSuffix(repeatIndex) ? `:repeat${repeatIndex}` : '';
535 return getScopedCacheKey(
536 `fetch:v3:${hashFetchCacheKey({
537 format,
538 headers: getHeadersForCacheKey(url, options),
539 method,
540 options: optionsForCacheKey.identity,
541 url: getUrlForFetchCacheKey(url),
542 })}${repeatSuffix}`,
543 );
544}
545
546function getAbortSignalId(signal: AbortSignal) {
547 let signalId = abortSignalIds.get(signal);

Callers 1

fetchWithCacheFunction · 0.85

Calls 7

getBodyForFetchCacheKeyFunction · 0.85
getScopedCacheKeyFunction · 0.85
hashFetchCacheKeyFunction · 0.85
getHeadersForCacheKeyFunction · 0.85
getUrlForFetchCacheKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…