(url: string, storetype?: string, signal?: AbortSignal)
| 531 | } |
| 532 | |
| 533 | async addToCache(url: string, storetype?: string, signal?: AbortSignal): Promise<void> { |
| 534 | await this.initDB(); // await the initDB process |
| 535 | // If already cached, nothing to do |
| 536 | const isInDB = await this.isUrlInDB(url); |
| 537 | if (isInDB) { |
| 538 | return; |
| 539 | } |
| 540 | try { |
| 541 | const response = await fetch(url, signal ? { signal } : undefined); |
| 542 | if (!response.ok) { |
| 543 | throw new Error('Network response was not ok'); |
| 544 | } |
| 545 | const response_copy = response.clone(); |
| 546 | await this.addToIndexedDB(url, response_copy, storetype); |
| 547 | } catch (error) { |
| 548 | throw Error("Failed to store " + url + " with error: " + error); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | async hasAllKeys(keys: string[]): Promise<boolean> { |
| 553 | await this.initDB(); // Ensure the DB is initialized |
no test coverage detected