Cache all the things
This commit is contained in:
@ -15,7 +15,7 @@ export interface KeyedHookFilter {
|
||||
export abstract class FeedCache<TCached> {
|
||||
#name: string;
|
||||
#hooks: Array<KeyedHookFilter> = [];
|
||||
#snapshot: Readonly<Array<TCached>> = [];
|
||||
#snapshot: Array<TCached> = [];
|
||||
#changed = true;
|
||||
#hits = 0;
|
||||
#miss = 0;
|
||||
@ -37,6 +37,10 @@ export abstract class FeedCache<TCached> {
|
||||
}, 30_000);
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
async preload() {
|
||||
const keys = (await this.table?.toCollection().primaryKeys()) ?? [];
|
||||
this.onTable = new Set<string>(keys.map(a => a as string));
|
||||
@ -111,7 +115,7 @@ export abstract class FeedCache<TCached> {
|
||||
this.notifyChange([k]);
|
||||
}
|
||||
|
||||
async bulkSet(obj: Array<TCached>) {
|
||||
async bulkSet(obj: Array<TCached> | Readonly<Array<TCached>>) {
|
||||
if (this.table) {
|
||||
await this.table.bulkPut(obj);
|
||||
obj.forEach(a => this.onTable.add(this.key(a)));
|
||||
|
Reference in New Issue
Block a user