jin-frame / frames/RequestDedupeManager / RequestDedupeManager
Class: RequestDedupeManager
Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:13
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:83
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<T
>(cacheKey
,requesterFn
):Promise
<DedupeResult
<T
>>
Defined in: packages/jin-frame/src/frames/RequestDedupeManager.ts:40
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.
Type Parameters
T
T
The expected response data type
Parameters
cacheKey
string
Unique identifier for the request used for deduplication (generated by JinFrame.getCacheKey())
requesterFn
() => Promise
<AxiosResponse
<T
, any
, { }>>
Function that performs the actual HTTP request
Returns
Promise
<DedupeResult
<T
>>
Promise resolving to DedupeResult containing the response and deduplication flag
Example
// Cache key is typically generated by JinFrame.getCacheKey()
const frame = GetUserFrame.of({ id: '123' });
const cacheKey = frame.getCacheKey();
const result = await RequestDedupeManager.dedupe(
cacheKey,
() => axios.get('/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:73
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:93
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