MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / getBodyForFetchCacheKey

Function getBodyForFetchCacheKey

src/cache.ts:452–483  ·  view source on GitHub ↗
(body: RequestInit['body'] | ReadableStream | null | undefined)

Source from the content-addressed store, hash-verified

450}
451
452function getBodyForFetchCacheKey(body: RequestInit['body'] | ReadableStream | null | undefined) {
453 if (body == null) {
454 return { cacheable: true, identity: undefined };
455 }
456
457 if (typeof body === 'string') {
458 return {
459 cacheable: true,
460 identity: { type: 'string', value: getBodyStringForFetchCacheKey(body) },
461 };
462 }
463
464 if (typeof URLSearchParams !== 'undefined' && body instanceof URLSearchParams) {
465 return {
466 cacheable: true,
467 identity: { type: 'url-search-params', value: getSearchParamsForFetchCacheKey(body) },
468 };
469 }
470
471 if (body instanceof ArrayBuffer) {
472 return { cacheable: true, identity: { type: 'array-buffer', ...hashBytesForCacheKey(body) } };
473 }
474
475 if (ArrayBuffer.isView(body)) {
476 return {
477 cacheable: true,
478 identity: { type: body.constructor.name, ...hashBytesForCacheKey(body) },
479 };
480 }
481
482 return { cacheable: false, identity: undefined };
483}
484
485function getOptionsForFetchCacheKey(options: RequestInit, bodyIdentity: unknown) {
486 const identity: Record<string, unknown> = {};

Callers 1

getFetchCacheKeyFunction · 0.85

Calls 3

hashBytesForCacheKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…