| 41 | * Common Interface for the artifact cache |
| 42 | */ |
| 43 | export interface ArtifactCacheTemplate { |
| 44 | /** |
| 45 | * Retrieve data object that corresponds to `url` from cache. If data object does not exist in |
| 46 | * cache, fetch the data and then add to cache. |
| 47 | * |
| 48 | * @param url The url to the data to be cached. |
| 49 | * @param storetype This field is required so that `ArtifactIndexedDBCache` can store the |
| 50 | * actual data object (see `addToCache()`), while `ArtifactCache` which uses the Cache API can |
| 51 | * return the actual data object rather than the request. There are two options: |
| 52 | * 1. "json": returns equivalent to `fetch(url).json()` |
| 53 | * 2. "arraybuffer": returns equivalent to `fetch(url).arraybuffer()` |
| 54 | * @param signal An optional AbortSignal allowing user to abort the fetching before its completion. |
| 55 | * @return The data object (i.e. users do not need to call `.json()` or `.arraybuffer()`). |
| 56 | * |
| 57 | * Note: This is an async function. |
| 58 | */ |
| 59 | fetchWithCache(url: string, storetype?: string, signal?: AbortSignal): Promise<any>; |
| 60 | |
| 61 | /** |
| 62 | * Fetch data from url and add into cache. If already exists in cache, should return instantly. |
| 63 | * |
| 64 | * @param url The url to the data to be cached. |
| 65 | * @param storetype Only applies to `ArtifactIndexedDBCache`. Since `indexedDB` stores the actual |
| 66 | * @param signal An optional AbortSignal to abort data retrival. |
| 67 | * data rather than a request, we specify `storagetype`. There are two options: |
| 68 | * 1. "json": IndexedDB stores `fetch(url).json()` |
| 69 | * 2. "arraybuffer": IndexedDB stores `fetch(url).arrayBuffer()` |
| 70 | * |
| 71 | * Note: This is an async function. |
| 72 | */ |
| 73 | addToCache(url: string, storetype?: string, signal?: AbortSignal): Promise<void>; |
| 74 | |
| 75 | /** |
| 76 | * check if cache has all keys in Cache |
| 77 | * |
| 78 | * Note: This is an async function. |
| 79 | */ |
| 80 | hasAllKeys(keys: string[]): Promise<boolean>; |
| 81 | |
| 82 | /** |
| 83 | * Delete url in cache if url exists |
| 84 | * |
| 85 | * Note: This is an async function. |
| 86 | */ |
| 87 | deleteInCache(url: string): Promise<void>; |
| 88 | } |
| 89 | |
| 90 | export type ArtifactCacheType = "cache" | "indexeddb" | "cross-origin" | "opfs"; |
| 91 |
no outgoing calls
no test coverage detected
searching dependent graphs…