Move default hash times to var

This commit is contained in:
Ajay Ramachandran 2021-12-03 00:12:08 -05:00
parent 5a69de730c
commit 8d533d0e94

View file

@ -4,8 +4,11 @@ import { HashedValue } from "../types/hash.model";
import { Logger } from "../utils/logger";
import { getHash } from "../utils/getHash";
export async function getHashCache<T extends string>(value: T, times = 5000): Promise<T & HashedValue> {
if (times === 5000) {
const defaultedHashTimes = 5000;
const cachedHashTimes = defaultedHashTimes - 1;
export async function getHashCache<T extends string>(value: T, times = defaultedHashTimes): Promise<T & HashedValue> {
if (times === defaultedHashTimes) {
const hashKey = getHash(value, 1);
const result: HashedValue = await getFromRedis(hashKey);
return result as T & HashedValue;
@ -25,7 +28,7 @@ async function getFromRedis<T extends string>(key: HashedValue): Promise<T & Has
// If all else, continue on hashing
}
}
const data = getHash(key, 5000-1);
const data = getHash(key, cachedHashTimes);
redis.setAsync(key, data);
return data as T & HashedValue;