source: frontend/node_modules/workbox-strategies/src/CacheOnly.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9import {assert} from 'workbox-core/_private/assert.js';
10import {logger} from 'workbox-core/_private/logger.js';
11import {WorkboxError} from 'workbox-core/_private/WorkboxError.js';
12
13import {Strategy} from './Strategy.js';
14import {StrategyHandler} from './StrategyHandler.js';
15import {messages} from './utils/messages.js';
16import './_version.js';
17
18/**
19 * An implementation of a [cache-only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
20 * request strategy.
21 *
22 * This class is useful if you want to take advantage of any
23 * [Workbox plugins](https://developer.chrome.com/docs/workbox/using-plugins/).
24 *
25 * If there is no cache match, this will throw a `WorkboxError` exception.
26 *
27 * @extends workbox-strategies.Strategy
28 * @memberof workbox-strategies
29 */
30class CacheOnly extends Strategy {
31 /**
32 * @private
33 * @param {Request|string} request A request to run this strategy for.
34 * @param {workbox-strategies.StrategyHandler} handler The event that
35 * triggered the request.
36 * @return {Promise<Response>}
37 */
38 async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
39 if (process.env.NODE_ENV !== 'production') {
40 assert!.isInstance(request, Request, {
41 moduleName: 'workbox-strategies',
42 className: this.constructor.name,
43 funcName: 'makeRequest',
44 paramName: 'request',
45 });
46 }
47
48 const response = await handler.cacheMatch(request);
49
50 if (process.env.NODE_ENV !== 'production') {
51 logger.groupCollapsed(
52 messages.strategyStart(this.constructor.name, request),
53 );
54 if (response) {
55 logger.log(
56 `Found a cached response in the '${this.cacheName}' ` + `cache.`,
57 );
58 messages.printFinalResponse(response);
59 } else {
60 logger.log(`No response found in the '${this.cacheName}' cache.`);
61 }
62 logger.groupEnd();
63 }
64
65 if (!response) {
66 throw new WorkboxError('no-response', {url: request.url});
67 }
68 return response;
69 }
70}
71
72export {CacheOnly};
Note: See TracBrowser for help on using the repository browser.