1e8475456a
- Make the gateway fetches guilds from Discord response - Fetch guilds with only ID and client - Make more types - Fix lint errors Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com> Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com> Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com> Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
46 lines
1 KiB
TypeScript
46 lines
1 KiB
TypeScript
let caches: any = {}
|
|
|
|
const get = (cacheName: string, key: string) => {
|
|
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) => {
|
|
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) => {
|
|
const gotCache: Map<string, any> = caches[cacheName]
|
|
if (gotCache === undefined || !(gotCache instanceof Map)) {
|
|
return
|
|
}
|
|
|
|
return gotCache.delete(key)
|
|
}
|
|
|
|
const deleteCache = (cacheName: string) => {
|
|
const gotCache = caches[cacheName]
|
|
if (gotCache === undefined) {
|
|
return
|
|
}
|
|
|
|
delete caches[cacheName]
|
|
}
|
|
|
|
const resetCaches = () => {
|
|
caches = {}
|
|
}
|
|
|
|
export { get, set, del, deleteCache, resetCaches }
|