harmony/src/models/cache.ts
Helloyunho e899738b55 Has some errors but since we didn't committed so long
Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com>
Co-Authored-By: Lee Hyun <ink0416@naver.com>
Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com>
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com>
2020-10-29 23:43:27 +09:00

48 lines
1.2 KiB
TypeScript

let caches: any = {}
const get = (cacheName: string, key: string): any => {
const gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
return undefined
}
const gotMap = gotCache.get(key)
return gotMap
}
const set = (cacheName: string, key: string, value: any): any => {
let gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
gotCache = caches[cacheName] = new Map<string, any>()
}
gotCache.set(key, value)
return value
}
const del = (cacheName: string, key: string): boolean | undefined => {
const gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
return
}
return gotCache.delete(key)
}
const deleteCache = (cacheName: string): void => {
const gotCache = caches[cacheName]
if (gotCache === undefined) {
return
}
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete caches[cacheName]
}
const resetCaches = (): void => {
caches = {}
}
export default { get, set, del, deleteCache, resetCaches }
export { get, set, del, deleteCache, resetCaches }