import BaseModel from "Common/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel"; import Dictionary from "Common/Types/Dictionary"; import { JSONValue } from "Common/Types/JSON"; export default abstract class LocalCache { private static cache: Dictionary = {}; public static setJSON( namespace: string, key: string, value: JSONValue, ): void { this.cache[namespace + "." + key] = value; } public static setString(namespace: string, key: string, value: string): void { this.cache[namespace + "." + key] = value; } public static setNumber(namespace: string, key: string, value: number): void { this.cache[namespace + "." + key] = value; } public static setModel( namespace: string, key: string, value: BaseModel, ): void { this.cache[namespace + "." + key] = value; } public static getModel( namespace: string, key: string, ): TBaseModel { return this.cache[namespace + "." + key] as TBaseModel; } public static getJSON(namespace: string, key: string): JSONValue { return this.cache[namespace + "." + key] as JSONValue; } public static getString(namespace: string, key: string): string { return this.cache[namespace + "." + key] as string; } public static getNumber(namespace: string, key: string): number { return this.cache[namespace + "." + key] as number; } public static async getOrSetString( namespace: string, key: string, getStringFunction: () => Promise, ): Promise { if (!LocalCache.getString(namespace, key)) { LocalCache.setString(namespace, key, await getStringFunction()); } return LocalCache.getString(namespace, key); } public static hasValue(namespace: string, key: string): boolean { return Boolean(this.cache[namespace + "." + key]); } }