MCPcopy
hub / github.com/angular/angular / CacheDatabase

Class CacheDatabase

packages/service-worker/worker/src/db-cache.ts:17–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 * state within mock `Response` objects.
16 */
17export class CacheDatabase implements Database {
18 private cacheNamePrefix = 'db';
19 private tables = new Map<string, CacheTable>();
20
21 constructor(private adapter: Adapter) {}
22
23 'delete'(name: string): Promise<boolean> {
24 if (this.tables.has(name)) {
25 this.tables.delete(name);
26 }
27 return this.adapter.caches.delete(`${this.cacheNamePrefix}:${name}`);
28 }
29
30 async list(): Promise<string[]> {
31 const prefix = `${this.cacheNamePrefix}:`;
32 const allCacheNames = await this.adapter.caches.keys();
33 const dbCacheNames = allCacheNames.filter((name) => name.startsWith(prefix));
34
35 // Return the un-prefixed table names, so they can be used with other `CacheDatabase` methods
36 // (for example, for opening/deleting a table).
37 return dbCacheNames.map((name) => name.slice(prefix.length));
38 }
39
40 async open(name: string, cacheQueryOptions?: CacheQueryOptions): Promise<Table> {
41 if (!this.tables.has(name)) {
42 const cache = await this.adapter.caches.open(`${this.cacheNamePrefix}:${name}`);
43 const table = new CacheTable(name, cache, this.adapter, cacheQueryOptions);
44 this.tables.set(name, table);
45 }
46 return this.tables.get(name)!;
47 }
48}
49
50/**
51 * A `Table` backed by a `Cache`.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…