From f1405fa8a1c7c8d301f24c9f4c9fe3e157eaab14 Mon Sep 17 00:00:00 2001 From: Skillz Date: Tue, 15 Sep 2020 09:14:43 -0400 Subject: [PATCH] work on custom cache --- src/controllers/cache.ts | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/controllers/cache.ts diff --git a/src/controllers/cache.ts b/src/controllers/cache.ts new file mode 100644 index 000000000..6eed28bb6 --- /dev/null +++ b/src/controllers/cache.ts @@ -0,0 +1,51 @@ +import { Channel } from "../structures/channel.ts"; +import { Guild } from "../structures/guild.ts"; +import { Message } from "../structures/message.ts"; +import { cache } from "../utils/cache.ts"; +import { Collection } from "../utils/collection.ts"; + +export type TableName = "guilds" | "channels" | "messages"; + +export function test( + test: "guilds", + key: string, + value: Guild, +): Promise>; +export function test( + test: "channels", + key: string, + value: Channel, +): Promise>; +export function test( + test: "messages", + key: string, + value: Message, +): Promise>; +export async function test(table: TableName, key: string, value: unknown) { + return cache[table].set(key, value); +} + +export let cacheHandlers = { + get: async function (table: TableName, key: string) { + return cache[table].get(key); + }, + delete: async function (table: TableName, key: string) { + return cache[table].delete(key); + }, + set: async function ( + table: TableName, + key: string, + value: Channel | Guild | Message, + ) { + return cache[table].set(key, value); + }, +}; + +export type CacheHandlers = typeof cacheHandlers; + +export function updateCacheHandlers(newCacheHandlers: CacheHandlers) { + cacheHandlers = { + ...cacheHandlers, + ...newCacheHandlers, + }; +}