clone of repo on github
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
917 B

export type NpubMetadata = { name?: string; displayName?: string };
class NpubCache {
private cache: Record<string, NpubMetadata> = {};
get(key: string): NpubMetadata | undefined {
return this.cache[key];
}
set(key: string, value: NpubMetadata): void {
this.cache[key] = value;
}
has(key: string): boolean {
return key in this.cache;
}
delete(key: string): boolean {
if (key in this.cache) {
delete this.cache[key];
return true;
}
return false;
}
deleteMany(keys: string[]): number {
let deleted = 0;
for (const key of keys) {
if (this.delete(key)) {
deleted++;
}
}
return deleted;
}
clear(): void {
this.cache = {};
}
size(): number {
return Object.keys(this.cache).length;
}
getAll(): Record<string, NpubMetadata> {
return { ...this.cache };
}
}
export const npubCache = new NpubCache();