in workbox-v4.3.1/workbox-core.dev.js [736:848]
url: getFriendlyURL(request.url),
method: request.method
});
}
}
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'write'
});
if (!response) {
{
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
}
throw new WorkboxError('cache-put-with-no-response', {
url: getFriendlyURL(effectiveRequest.url)
});
}
let responseToCache = await _isResponseSafeToCache({
event,
plugins,
response,
request: effectiveRequest
});
if (!responseToCache) {
{
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
}
return;
}
const cache = await caches.open(cacheName);
const updatePlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_DID_UPDATE);
let oldResponse = updatePlugins.length > 0 ? await matchWrapper({
cacheName,
matchOptions,
request: effectiveRequest
}) : null;
{
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
}
try {
await cache.put(effectiveRequest, responseToCache);
} catch (error) {
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
if (error.name === 'QuotaExceededError') {
await executeQuotaErrorCallbacks();
}
throw error;
}
for (let plugin of updatePlugins) {
await plugin[pluginEvents.CACHE_DID_UPDATE].call(plugin, {
cacheName,
event,
oldResponse,
newResponse: responseToCache,
request: effectiveRequest
});
}
};
/**
* This is a wrapper around cache.match().
*
* @param {Object} options
* @param {string} options.cacheName Name of the cache to match against.
* @param {Request} options.request The Request that will be used to look up
* cache entries.
* @param {Event} [options.event] The event that propted the action.
* @param {Object} [options.matchOptions] Options passed to cache.match().
* @param {Array<Object>} [options.plugins=[]] Array of plugins.
* @return {Response} A cached response if available.
*
* @private
* @memberof module:workbox-core
*/
const matchWrapper = async ({
cacheName,
request,
event,
matchOptions,
plugins = []
}) => {
const cache = await caches.open(cacheName);
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'read'
});
let cachedResponse = await cache.match(effectiveRequest, matchOptions);
{
if (cachedResponse) {
logger.debug(`Found a cached response in '${cacheName}'.`);
} else {
logger.debug(`No cached response found in '${cacheName}'.`);
}
}
for (const plugin of plugins) {
if (pluginEvents.CACHED_RESPONSE_WILL_BE_USED in plugin) {
cachedResponse = await plugin[pluginEvents.CACHED_RESPONSE_WILL_BE_USED].call(plugin, {