2020-11-02 06:58:23 +00:00
|
|
|
import { Client } from '../models/client.ts'
|
2020-11-01 11:22:09 +00:00
|
|
|
|
|
|
|
export class GatewayCache {
|
2020-11-02 06:58:23 +00:00
|
|
|
client: Client
|
|
|
|
cacheName: string = 'discord_gateway_cache'
|
2020-11-01 11:22:09 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
constructor (client: Client, cacheName?: string) {
|
|
|
|
this.client = client
|
|
|
|
if (cacheName !== undefined) this.cacheName = cacheName
|
|
|
|
}
|
2020-11-01 11:22:09 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
async get (key: string): Promise<undefined | any> {
|
|
|
|
const result = await this.client.cache.get(this.cacheName, key)
|
|
|
|
return result
|
|
|
|
}
|
2020-11-01 11:22:09 +00:00
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
async set (key: string, value: any): Promise<any> {
|
|
|
|
const result = await this.client.cache.set(this.cacheName, key, value)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete (key: string): Promise<boolean> {
|
|
|
|
console.log(`[GatewayCache] DEL ${key}`)
|
|
|
|
const result = await this.client.cache.delete(this.cacheName, key)
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|