diff --git a/src/config.ts b/src/config.ts index e1c3cba..b39effa 100644 --- a/src/config.ts +++ b/src/config.ts @@ -132,7 +132,8 @@ addDefaults(config, { host: "", port: 0 }, - disableOfflineQueue: true + disableOfflineQueue: true, + expiryTime: 24 * 60 * 60, } }); loadFromEnv(config); diff --git a/src/types/config.model.ts b/src/types/config.model.ts index 8b6bbd1..da01d60 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -3,6 +3,7 @@ import * as redis from "redis"; interface RedisConfig extends redis.RedisClientOptions { enabled: boolean; + expiryTime: number; } export interface CustomPostgresConfig extends PoolConfig { diff --git a/src/utils/queryCacher.ts b/src/utils/queryCacher.ts index c3548be..3abeb31 100644 --- a/src/utils/queryCacher.ts +++ b/src/utils/queryCacher.ts @@ -3,8 +3,7 @@ import { Logger } from "../utils/logger"; import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey } from "./redisKeys"; import { Service, VideoID, VideoIDHash } from "../types/segments.model"; import { Feature, HashedUserID, UserID } from "../types/user.model"; - -const expiryTime = 2 * 60 * 60; +import { config } from "../config"; async function get(fetchFromDB: () => Promise, key: string): Promise { try { @@ -18,7 +17,7 @@ async function get(fetchFromDB: () => Promise, key: string): Promise { const data = await fetchFromDB(); - redis.setEx(key, expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err)); + redis.setEx(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err)); return data; }