This commit is contained in:
DjDeveloperr 2021-03-19 17:07:57 +05:30
parent 6641778578
commit 4f71717047
1 changed files with 14 additions and 0 deletions

View File

@ -67,6 +67,20 @@ export class BaseManager<T, T2> {
yield* readable.getIterator()
}
async fetch(...args: unknown[]): Promise<T2 | undefined> {
return undefined
}
/** Try to get value from cache, if not found then fetch */
async resolve(key: string): Promise<T2 | undefined> {
const cacheValue = await this.get(key)
if (cacheValue !== undefined) return cacheValue
else {
const fetchValue = await this.fetch(key).catch(() => undefined)
if (fetchValue !== undefined) return fetchValue
}
}
/** Deletes everything from Cache */
flush(): any {
return this.client.cache.deleteCache(this.cacheName)