mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 13:37:01 +03:00
Configurable expiry time
This commit is contained in:
@@ -132,7 +132,8 @@ addDefaults(config, {
|
|||||||
host: "",
|
host: "",
|
||||||
port: 0
|
port: 0
|
||||||
},
|
},
|
||||||
disableOfflineQueue: true
|
disableOfflineQueue: true,
|
||||||
|
expiryTime: 24 * 60 * 60,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
loadFromEnv(config);
|
loadFromEnv(config);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as redis from "redis";
|
|||||||
|
|
||||||
interface RedisConfig extends redis.RedisClientOptions {
|
interface RedisConfig extends redis.RedisClientOptions {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
expiryTime: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomPostgresConfig extends PoolConfig {
|
export interface CustomPostgresConfig extends PoolConfig {
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ import { Logger } from "../utils/logger";
|
|||||||
import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey } from "./redisKeys";
|
import { skipSegmentsHashKey, skipSegmentsKey, reputationKey, ratingHashKey, skipSegmentGroupsKey, userFeatureKey } from "./redisKeys";
|
||||||
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
import { Service, VideoID, VideoIDHash } from "../types/segments.model";
|
||||||
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
import { Feature, HashedUserID, UserID } from "../types/user.model";
|
||||||
|
import { config } from "../config";
|
||||||
const expiryTime = 2 * 60 * 60;
|
|
||||||
|
|
||||||
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
||||||
try {
|
try {
|
||||||
@@ -18,7 +17,7 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
|
|||||||
|
|
||||||
const data = await fetchFromDB();
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user