Fixed service worker cache
This commit is contained in:
parent
2cfc36ce0d
commit
7af6ec2790
@ -388,11 +388,9 @@ class MyServiceWorker {
|
|||||||
// MyCache is the cache used by the service worker.
|
// MyCache is the cache used by the service worker.
|
||||||
class MyCache {
|
class MyCache {
|
||||||
version: string
|
version: string
|
||||||
cache: Cache
|
|
||||||
|
|
||||||
constructor(version: string) {
|
constructor(version: string) {
|
||||||
this.version = version
|
this.version = version
|
||||||
caches.open(this.version).then(newCache => this.cache = newCache)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@ -402,14 +400,16 @@ class MyCache {
|
|||||||
async store(request: RequestInfo, response: Response) {
|
async store(request: RequestInfo, response: Response) {
|
||||||
try {
|
try {
|
||||||
// This can fail if the disk space quota has been exceeded.
|
// This can fail if the disk space quota has been exceeded.
|
||||||
await this.cache.put(request, response)
|
let cache = await caches.open(this.version)
|
||||||
|
await cache.put(request, response)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log("Disk quota exceeded, can't store in cache:", request, response)
|
console.log("Disk quota exceeded, can't store in cache:", request, response, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async serve(request: RequestInfo): Promise<Response> {
|
async serve(request: RequestInfo): Promise<Response> {
|
||||||
let matching = await this.cache.match(request)
|
let cache = await caches.open(this.version)
|
||||||
|
let matching = await cache.match(request)
|
||||||
|
|
||||||
if(matching) {
|
if(matching) {
|
||||||
return matching
|
return matching
|
||||||
|
Loading…
Reference in New Issue
Block a user