From 2d386239741945624c965a0d136c4ec5934d24e4 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 24 Jun 2019 15:04:12 +0300 Subject: [PATCH] refactor(service-worker): make the caching behavior more explicit (#30977) This commit doesn't change the behavior wrt caching, but it makes it more explicit that only non-timed-out responses are cached. In case of a timeout, `res` would be set to a programmatically created 504 `Response`, so `cacheResponse()` (which checks for `res.ok`) would not have cached it anyway, but this makes change makes it more explicit (and more similar to the equivalent part in [handleFetchWithFreshness()][1]). [1]: https://github.com/angular/angular/blob/2b4d5c754/packages/service-worker/worker/src/data.ts#L379-L388 PR Close #30977 --- packages/service-worker/worker/src/data.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/service-worker/worker/src/data.ts b/packages/service-worker/worker/src/data.ts index 85e797c91c..3b476111c9 100644 --- a/packages/service-worker/worker/src/data.ts +++ b/packages/service-worker/worker/src/data.ts @@ -354,10 +354,11 @@ export class DataGroup { // Cache the network response eventually. ctx.waitUntil(this.safeCacheResponse(req, networkFetch)); + } else { + // The request completed in time, so cache it inline with the response flow. + await this.cacheResponse(req, res, lru); } - // The request completed in time, so cache it inline with the response flow. - await this.cacheResponse(req, res, lru); return res; }