import { CacheableResponse } from 'workbox-cacheable-response';
async function saveResponse(url, cb) {
// If both statuses and headers are specified,
// then both conditions must be met for the Response to be considered cacheable.
const cacheable = new CacheableResponse({
statuses: [200]
});
const response = await cb();
if (cacheable.isResponseCacheable(response)) {
const cache = await caches.open('api-cache');
cache.put(url, response);
} else {
// Do something when the response can't be cached.
console.log('error occurred');
}
}
export default saveResponse;