File tree Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Expand file tree Collapse file tree 2 files changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -73,8 +73,6 @@ export class ResponseCache {
73
73
response : Response ;
74
74
ttl : number | null ;
75
75
} ) : Promise < void > => {
76
- // TODO: might be able to do ctx.waitUntil:
77
- // https://developers.cloudflare.com/workers/examples/cache-api
78
76
const body = await response . clone ( ) . text ( ) ;
79
77
const responseObject = {
80
78
status : response . status ,
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ interface HandleProxyOpts {
12
12
export const handleProxy = async ( {
13
13
request,
14
14
env,
15
+ ctx,
15
16
ttl,
16
17
pathname,
17
18
} : HandleProxyOpts ) : Promise < Response > => {
@@ -50,11 +51,13 @@ export const handleProxy = async ({
50
51
51
52
if ( response . ok ) {
52
53
console . log ( 'Writing 2xx response to cache: ' , { cacheKey, ttl } ) ;
53
- await responseCache . write ( {
54
+ const writeCachePromise = responseCache . write ( {
54
55
cacheKey,
55
56
ttl,
56
57
response,
57
58
} ) ;
59
+ // https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#waituntil
60
+ ctx . waitUntil ( writeCachePromise ) ;
58
61
} else {
59
62
console . log ( 'Not caching error or empty response.' ) ;
60
63
}
You can’t perform that action at this time.
0 commit comments