MCPcopy
hub / github.com/angular/angular / safeCacheResponse

Method safeCacheResponse

packages/service-worker/worker/src/data.ts:470–494  ·  view source on GitHub ↗
(
    req: Request,
    resOrPromise: Promise<Response> | Response,
    lru: LruList,
    okToCacheOpaque?: boolean,
  )

Source from the content-addressed store, hash-verified

468 }
469
470 private async safeCacheResponse(
471 req: Request,
472 resOrPromise: Promise<Response> | Response,
473 lru: LruList,
474 okToCacheOpaque?: boolean,
475 ): Promise<void> {
476 try {
477 const res = await resOrPromise;
478 try {
479 await this.cacheResponse(req, res, lru, okToCacheOpaque);
480 } catch (err) {
481 // Saving the API response failed. This could be a result of a full storage.
482 // Since this data is cached lazily and temporarily, continue serving clients as usual.
483 this.debugHandler.log(
484 err as Error,
485 `DataGroup(${this.config.name}@${this.config.version}).safeCacheResponse(${req.url}, status: ${res.status})`,
486 );
487
488 await this.detectStorageFull();
489 }
490 } catch {
491 // Request failed
492 // TODO: Handle this error somehow?
493 }
494 }
495
496 private async loadFromCache(
497 req: Request,

Callers 2

Calls 3

cacheResponseMethod · 0.95
detectStorageFullMethod · 0.95
logMethod · 0.65

Tested by

no test coverage detected