Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _respondFromCache({event, request}: {
request: Request,
event?: ExtendableEvent,
}): Promise {
return cacheWrapper.match({
cacheName: this._cacheName,
request,
event,
matchOptions: this._matchOptions,
plugins: this._plugins,
});
}
}
async handle({event, request}: RouteHandlerCallbackOptions): Promise {
const logs = [];
if (process.env.NODE_ENV !== 'production') {
assert!.isInstance(request, Request, {
moduleName: 'workbox-strategies',
className: 'CacheFirst',
funcName: 'makeRequest',
paramName: 'request',
});
}
let response = await cacheWrapper.match({
cacheName: this._cacheName,
request,
event,
matchOptions: this._matchOptions,
plugins: this._plugins,
});
let error;
if (!response) {
if (process.env.NODE_ENV !== 'production') {
logs.push(
`No response found in the '${this._cacheName}' cache. ` +
`Will respond with a network request.`);
}
try {
response = await this._getFromNetwork(request, event);
async handle({event, request}: RouteHandlerCallbackOptions): Promise {
const logs = [];
if (process.env.NODE_ENV !== 'production') {
assert!.isInstance(request, Request, {
moduleName: 'workbox-strategies',
className: 'StaleWhileRevalidate',
funcName: 'handle',
paramName: 'request',
});
}
const fetchAndCachePromise = this._getFromNetwork({request, event});
let response = await cacheWrapper.match({
cacheName: this._cacheName,
request,
event,
matchOptions: this._matchOptions,
plugins: this._plugins,
});
let error;
if (response) {
if (process.env.NODE_ENV !== 'production') {
logs.push(`Found a cached response in the '${this._cacheName}'` +
` cache. Will update with the network response in the background.`);
}
if (event) {
try {
event.waitUntil(fetchAndCachePromise);
async handle({event, request}: RouteHandlerCallbackOptions): Promise {
if (process.env.NODE_ENV !== 'production') {
assert!.isInstance(request, Request, {
moduleName: 'workbox-strategies',
className: 'CacheOnly',
funcName: 'makeRequest',
paramName: 'request',
});
}
const response = await cacheWrapper.match({
cacheName: this._cacheName,
request,
event,
matchOptions: this._matchOptions,
plugins: this._plugins,
});
if (process.env.NODE_ENV !== 'production') {
logger.groupCollapsed(
messages.strategyStart('CacheOnly', request));
if (response) {
logger.log(`Found a cached response in the '${this._cacheName}'` +
` cache.`);
messages.printFinalResponse(response);
} else {
logger.log(`No response found in the '${this._cacheName}' cache.`);