From 6b5c9a4ce70e49eac9668cbd60f4409da8285ac6 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sun, 25 May 2025 18:53:15 +0200 Subject: [PATCH] feat(extractor): cache not found results too --- src/extractor/ExtractorRegistry.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extractor/ExtractorRegistry.ts b/src/extractor/ExtractorRegistry.ts index 6386c34..ab01cfd 100644 --- a/src/extractor/ExtractorRegistry.ts +++ b/src/extractor/ExtractorRegistry.ts @@ -12,7 +12,7 @@ import { NotFoundError } from '../error'; export class ExtractorRegistry { private readonly logger: winston.Logger; private readonly extractors: Extractor[]; - private readonly urlResultCache: TTLCache; + private readonly urlResultCache: TTLCache; constructor(logger: winston.Logger, fetcher: Fetcher) { this.logger = logger; @@ -27,7 +27,7 @@ export class ExtractorRegistry { readonly handle = async (ctx: Context, url: URL, countryCode: string): Promise => { let urlResult = this.urlResultCache.get(url.href); - if (urlResult) { + if (this.urlResultCache.has(url.href)) { return urlResult; } @@ -38,6 +38,8 @@ export class ExtractorRegistry { urlResult = await extractor.extract(ctx, url, countryCode); } catch (error) { if (error instanceof NotFoundError) { + this.urlResultCache.set(url.href, urlResult, { ttl: extractor.ttl }); + return undefined; }