Don't cache empty arrays

Maybe help with #483
This commit is contained in:
Ajay
2022-07-15 00:21:08 -04:00
parent 5c089dab13
commit 9ab939456b
2 changed files with 7 additions and 5 deletions

View File

@@ -4,7 +4,7 @@ import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, ski
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
import { Feature, HashedUserID, UserID } from "../types/user.model";
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
async function get<T>(fetchFromDB: () => Promise<T>, key: string, cacheEmpty = true): Promise<T> {
try {
const reply = await redis.get(key);
if (reply) {
@@ -16,7 +16,9 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
const data = await fetchFromDB();
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
if (cacheEmpty || data) {
redis.set(key, JSON.stringify(data)).catch((err) => Logger.error(err));
}
return data;
}