harmony/src/managers/gatewayCache.ts

32 lines
887 B
TypeScript
Raw Normal View History

import { Client } from '../models/client.ts'
2020-12-03 04:06:41 +00:00
/**
* Cache Manager used for Caching values related to Gateway connection
*
* In case of Redis, this will persistently cache session ID and seq for fast resumes.
*/
export class GatewayCache {
client: Client
cacheName: string = 'discord_gateway_cache'
2020-12-02 12:29:52 +00:00
constructor(client: Client, cacheName?: string) {
this.client = client
if (cacheName !== undefined) this.cacheName = cacheName
}
2020-12-02 12:29:52 +00:00
async get(key: string): Promise<undefined | any> {
const result = await this.client.cache.get(this.cacheName, key)
return result
}
2020-12-02 12:29:52 +00:00
async set(key: string, value: any): Promise<any> {
const result = await this.client.cache.set(this.cacheName, key, value)
return result
}
2020-12-02 12:29:52 +00:00
async delete(key: string): Promise<boolean> {
const result = await this.client.cache.delete(this.cacheName, key)
return result
}
}