refactor: make cache ttl configurable per embed extractor
This commit is contained in:
parent
f2389f428b
commit
09ee685d22
4 changed files with 8 additions and 2 deletions
|
|
@ -8,6 +8,8 @@ export class Dropload implements EmbedExtractor {
|
|||
|
||||
readonly label = 'Dropload';
|
||||
|
||||
readonly ttl = 900000; // 15m
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
|
||||
constructor(fetcher: Fetcher) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ export class SuperVideo implements EmbedExtractor {
|
|||
|
||||
readonly label = 'SuperVideo';
|
||||
|
||||
readonly ttl = 900000; // 15m
|
||||
|
||||
private readonly fetcher: Fetcher;
|
||||
|
||||
constructor(fetcher: Fetcher) {
|
||||
|
|
|
|||
|
|
@ -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>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue