From 0a57114c7d8e5d6c8944e4c8cbacaa2f795831d8 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sun, 11 May 2025 21:39:36 +0000 Subject: [PATCH] refactor: better names for the cache properties --- src/embed-extractor/EmbedExtractors.ts | 8 ++++---- src/utils/Fetcher.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/embed-extractor/EmbedExtractors.ts b/src/embed-extractor/EmbedExtractors.ts index 7ccfa18..5966a69 100644 --- a/src/embed-extractor/EmbedExtractors.ts +++ b/src/embed-extractor/EmbedExtractors.ts @@ -5,15 +5,15 @@ import { Context, UrlResult } from '../types'; export class EmbedExtractors { private readonly embedExtractors: EmbedExtractor[]; - private readonly cache: TTLCache; + private readonly urlResultCache: TTLCache; constructor(embedExtractors: EmbedExtractor[]) { this.embedExtractors = embedExtractors; - this.cache = new TTLCache({ max: 1024, ttl: 900000 }); // 15m + this.urlResultCache = new TTLCache({ max: 1024, ttl: 900000 }); // 15m } readonly handle = async (ctx: Context, url: URL, language: string): Promise => { - let urlResult = this.cache.get(url.href); + let urlResult = this.urlResultCache.get(url.href); if (urlResult) { return urlResult; } @@ -24,7 +24,7 @@ export class EmbedExtractors { } urlResult = await embedExtractor.extract(ctx, url, language); - this.cache.set(url.href, urlResult); + this.urlResultCache.set(url.href, urlResult); return urlResult; }; diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 9c47242..b95d838 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -7,11 +7,11 @@ import { Context } from '../types'; export class Fetcher { private readonly fetch: FetchInterface; - private readonly cache: TTLCache; + private readonly ipUserAgentCache: TTLCache; constructor(fetch: FetchInterface) { this.fetch = fetch; - this.cache = new TTLCache({ max: 1024, ttl: 86400000 }); // 24h + this.ipUserAgentCache = new TTLCache({ max: 1024, ttl: 86400000 }); // 24h } readonly text = async (ctx: Context, uriOrRequest: string | Request, opts?: FetchOptions): Promise => { @@ -37,14 +37,14 @@ export class Fetcher { }; private readonly createUserAgentForIp = (ip: string): string => { - let userAgent = this.cache.get(ip); + let userAgent = this.ipUserAgentCache.get(ip); if (userAgent) { return userAgent; } userAgent = (new UserAgent()).toString(); - this.cache.set(ip, userAgent); + this.ipUserAgentCache.set(ip, userAgent); return userAgent; };