Skip to content

Commit efa2fd2

Browse files
authored
feat: allow to specify payload instance cache key in handleEndpoints (#14675)
This PR extends #13603 with allowing you to specify `payloadInstanceCacheKey` inside `handleEndpoints` and `createPayloadRequest`.
1 parent 8a3c6dc commit efa2fd2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/payload/src/utilities/createPayloadRequest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ type Args = {
1818
params?: {
1919
collection: string
2020
}
21+
payloadInstanceCacheKey?: string
2122
request: Request
2223
}
2324

2425
export const createPayloadRequest = async ({
2526
canSetHeaders,
2627
config: configPromise,
2728
params,
29+
payloadInstanceCacheKey,
2830
request,
2931
}: Args): Promise<PayloadRequest> => {
3032
const cookies = parseCookies(request.headers)
31-
const payload = await getPayload({ config: configPromise, cron: true })
33+
const payload = await getPayload({
34+
config: configPromise,
35+
cron: true,
36+
key: payloadInstanceCacheKey,
37+
})
3238

3339
const { config } = payload
3440
const localization = config.localization

packages/payload/src/utilities/handleEndpoints.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ export const handleEndpoints = async ({
6363
basePath = '',
6464
config: incomingConfig,
6565
path,
66+
payloadInstanceCacheKey,
6667
request,
6768
}: {
6869
basePath?: string
6970
config: Promise<SanitizedConfig> | SanitizedConfig
7071
/** Override path from the request */
7172
path?: string
73+
payloadInstanceCacheKey?: string
7274
request: Request
7375
}): Promise<Response> => {
7476
let handler!: PayloadHandler
@@ -122,14 +124,20 @@ export const handleEndpoints = async ({
122124
basePath,
123125
config: incomingConfig,
124126
path,
127+
payloadInstanceCacheKey,
125128
request: req,
126129
})
127130

128131
return response
129132
}
130133

131134
try {
132-
req = await createPayloadRequest({ canSetHeaders: true, config: incomingConfig, request })
135+
req = await createPayloadRequest({
136+
canSetHeaders: true,
137+
config: incomingConfig,
138+
payloadInstanceCacheKey,
139+
request,
140+
})
133141

134142
if (req.method?.toLowerCase() === 'options') {
135143
return Response.json(

0 commit comments

Comments
 (0)