Skip to content

jin-frame / frames/RequestDedupeManager / RequestDedupeManager

Class: RequestDedupeManager ​

Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:19

Manages request deduplication to prevent multiple identical HTTP requests from being sent simultaneously. When multiple requests with the same cache key are made, only the first request is actually sent, and all subsequent requests receive the same response.

The cache key is generated using the getCacheKey() method from JinFrame instances, which creates a unique identifier based on the request parameters and configuration.

Constructors ​

Constructor ​

new RequestDedupeManager(): RequestDedupeManager

Returns ​

RequestDedupeManager

Methods ​

clearAllPendingRequests() ​

static clearAllPendingRequests(): void

Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:105

Clears all pending requests from the cache. This method is primarily intended for testing purposes.

Returns ​

void

Warning ​

Use with caution in production as this will affect all pending requests


dedupe() ​

static dedupe(cacheKey, requesterFn): Promise<DedupeResult>

Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:46

Deduplicates HTTP requests based on cache key. If a request with the same cache key is already in progress, returns the result of that request. Otherwise, executes the new request and stores it for potential deduplication.

Parameters ​

cacheKey ​

string

Unique identifier for the request used for deduplication (generated by JinFrame._getCacheKey())

requesterFn ​

() => Promise<Response>

Function that performs the actual HTTP request

Returns ​

Promise<DedupeResult>

Promise resolving to DedupeResult containing the response and deduplication flag

Example ​

ts
// Cache key is typically generated by JinFrame._getCacheKey()
const frame = GetUserFrame.of({ id: '123' });
const cacheKey = frame._getCacheKey();

const result = await RequestDedupeManager.dedupe(
  cacheKey,
  () => fetch('/users/123')
);
console.log(result.isDeduped); // false for original request, true for duplicates

getPendingRequestsCount() ​

static getPendingRequestsCount(): number

Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:95

Returns the number of currently pending requests. Useful for debugging and monitoring request deduplication.

Returns ​

number

The count of pending requests


hasPendingRequest() ​

static hasPendingRequest(cacheKey): boolean

Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:115

Checks if a request with the given cache key is currently pending.

Parameters ​

cacheKey ​

string

The cache key to check

Returns ​

boolean

true if a request with this cache key is pending, false otherwise