From 698db97eb14b317d1e36c971bef50e45ff183f7e Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Thu, 5 Dec 2019 23:19:19 -0500 Subject: [PATCH] [+] Create get() method for cache --- src/logic/utils/cache-utils.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/logic/utils/cache-utils.ts b/src/logic/utils/cache-utils.ts index deb2af1..8aff3d5 100644 --- a/src/logic/utils/cache-utils.ts +++ b/src/logic/utils/cache-utils.ts @@ -2,4 +2,19 @@ export default class Cache { map: Map = new Map(); + + /** + * Get a cached value, or if not cached, cache it. + * + * @param name Name of the cached value + * @param callback Callback function + */ + public get(name: string, callback: () => any) + { + if (!this.map.has(name)) + { + this.map.set(name, callback()); + } + return this.map.get(name); + } }