refactor: make cache ttl configurable per embed extractor

This commit is contained in:
WebStreamr 2025-05-12 09:05:46 +00:00
parent f2389f428b
commit 09ee685d22
No known key found for this signature in database
4 changed files with 8 additions and 2 deletions

View file

@ -8,6 +8,8 @@ export class Dropload implements EmbedExtractor {
readonly label = 'Dropload';
readonly ttl = 900000; // 15m
private readonly fetcher: Fetcher;
constructor(fetcher: Fetcher) {

View file

@ -9,7 +9,7 @@ export class EmbedExtractors {
constructor(embedExtractors: EmbedExtractor[]) {
this.embedExtractors = embedExtractors;
this.urlResultCache = new TTLCache({ max: 1024, ttl: 900000 }); // 15m
this.urlResultCache = new TTLCache({ max: 1024 });
}
readonly handle = async (ctx: Context, url: URL, language: string): Promise<UrlResult> => {
@ -24,7 +24,7 @@ export class EmbedExtractors {
}
urlResult = await embedExtractor.extract(ctx, url, language);
this.urlResultCache.set(url.href, urlResult);
this.urlResultCache.set(url.href, urlResult, { ttl: embedExtractor.ttl });
return urlResult;
};

View file

@ -8,6 +8,8 @@ export class SuperVideo implements EmbedExtractor {
readonly label = 'SuperVideo';
readonly ttl = 900000; // 15m
private readonly fetcher: Fetcher;
constructor(fetcher: Fetcher) {

View file

@ -5,6 +5,8 @@ export interface EmbedExtractor {
readonly label: string;
readonly ttl: number;
readonly supports: (url: URL) => boolean;
readonly extract: (ctx: Context, url: URL, language: string) => Promise<UrlResult>;