In this cache API usage example am I right to assume that the line ctx.waitUntil(cache.put(cacheKey, response.clone()));
means the response will be returned not waiting for the caching to be done?
I am trying to make sure the user does not have to wait for caching to happen before having the response returned.
…and not using ctx.waitUntil()
and instead going for await cache.put()
would result in waiting for caching to happen. Is this logic correct?
That is correct, it won’t block your response and continue executing in the background, even after the response has returned.
The
waitUntil()
method extends the lifetime of thefetch
event. It accepts aPromise
-based task which the Workers runtime will execute before the handler terminates but without blocking the response. For example, this is ideal for caching responses or handling logging.
…and not using
ctx.waitUntil()
and instead going forawait cache.put()
would result in waiting for caching to happen.
That’s correct, because in that case you’re await
ing cache.put()
to be done first before continuing with the rest of your code.
Hi @g.andghuladze, your topic has a solution here.
Let us know what you think of the solution by logging in and give it a or
.
Solutions help the person that asked the question and anyone else that sees the answer later. Login to tell us what you think of the solution with a or
.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.