A powerful and extendable Discord bot, with it's own module system :3
thevoid.cafe/projects/voidy
1import type { Resource } from "../types/Resource";
2
3export class ResourceCache {
4 private store = new Map<string, Map<string, Resource>>();
5
6 set<T extends Resource>(type: string, id: string, resource: T): void {
7 if (!this.store.has(type)) this.store.set(type, new Map());
8 this.store.get(type)!.set(id, resource);
9 }
10
11 get<T extends Resource>(type: string, id: string): T | undefined {
12 return this.store.get(type)?.get(id) as T | undefined;
13 }
14
15 getAll<T extends Resource>(type: string): Map<string, T> {
16 return (this.store.get(type) as Map<string, T>) ?? new Map();
17 }
18}