Skip to content

Commit 06f01e9

Browse files
committed
fix: predicate cache logic
1 parent da1f44c commit 06f01e9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/core/handlers/RequestHandler.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ export abstract class RequestHandler<
133133
StrictRequest<DefaultBodyType>
134134
>()
135135

136-
static predicateCache = new WeakMap<StrictRequest<DefaultBodyType>, boolean>()
136+
static predicateCache = new WeakMap<
137+
StrictRequest<DefaultBodyType>,
138+
Map<RequestHandler, boolean>
139+
>()
137140

138141
private readonly __kind: HandlerKind
139142

@@ -259,16 +262,21 @@ export abstract class RequestHandler<
259262
parsedResult: ParsedResult
260263
resolutionContext?: ResponseResolutionContext
261264
}): Promise<boolean> {
262-
const existingPredicateResult = RequestHandler.predicateCache.get(
263-
args.request,
264-
)
265+
let handlerCache = RequestHandler.predicateCache.get(args.request)
266+
267+
if (handlerCache === undefined) {
268+
handlerCache = new Map()
269+
RequestHandler.predicateCache.set(args.request, handlerCache)
270+
}
271+
272+
const existingPredicateResult = handlerCache.get(this)
265273

266-
if (typeof existingPredicateResult !== 'undefined') {
274+
if (existingPredicateResult !== undefined) {
267275
return existingPredicateResult
268276
}
269277

270278
const predicateResult = await this.predicate(args)
271-
RequestHandler.predicateCache.set(args.request, predicateResult)
279+
handlerCache.set(this, predicateResult)
272280

273281
return predicateResult
274282
}

0 commit comments

Comments
 (0)