1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| caches.open('test-cache').then(cache => { cache.addAll(['/1.png', '/2.png']).then(() => { console.log('1 and 2 are cached.'); });
cache.add('/3.png').then(() => { console.log('3 is cached.'); }); });
caches.has('test-cache').then(flag => { console.log(flag); });
fetch('/4.png').then(response => { return caches.open('test-cache').then(cache => { return cache.put('/4.png', response); }); });
caches.open('test-cache').then(cache => { cache.keys().then(cached => { console.log(cached); }); });
caches.open('test-cache').then(cache => { cache.match('/3.png').then(matched => { console.log(matched); }); });
caches .open('test-cache') .then(cache => { cache.delete('/4.png').then(() => { console.log('4 is deleted'); }); }) .catch(error => { console.log(error); });
caches.delete('test-cache').then(() => { console.log('test-cache is deleted'); });
|