MCPcopy
hub / github.com/angular/angular / maybeUpdate

Function maybeUpdate

packages/service-worker/worker/src/assets.ts:472–498  ·  view source on GitHub ↗

* Possibly update a resource, if it's expired and needs to be updated. A no-op otherwise.

(
    updateFrom: UpdateSource,
    req: Request,
    cache: Cache,
  )

Source from the content-addressed store, hash-verified

470 * Possibly update a resource, if it's expired and needs to be updated. A no-op otherwise.
471 */
472 protected async maybeUpdate(
473 updateFrom: UpdateSource,
474 req: Request,
475 cache: Cache,
476 ): Promise<boolean> {
477 const url = this.adapter.normalizeUrl(req.url);
478 // Check if this resource is hashed and already exists in the cache of a prior version.
479 if (this.hashes.has(url)) {
480 const hash = this.hashes.get(url)!;
481
482 // Check the caches of prior versions, using the hash to ensure the correct version of
483 // the resource is loaded.
484 const res = await updateFrom.lookupResourceWithHash(url, hash);
485
486 // If a previously cached version was available, copy it over to this cache.
487 if (res !== null) {
488 // Copy to this cache.
489 await cache.put(req, res);
490
491 // No need to do anything further with this resource, it's now cached properly.
492 return true;
493 }
494 }
495
496 // No up-to-date version of this resource could be found.
497 return false;
498 }
499
500 /**
501 * Create a new `Request` based on the specified URL and `RequestInit` options, preserving only

Callers

nothing calls this directly

Calls 5

normalizeUrlMethod · 0.80
hasMethod · 0.65
getMethod · 0.65
putMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…