From 5ea34f66dd5106112eae792e657af51513064df4 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Wed, 3 Sep 2025 12:48:21 +0000 Subject: [PATCH] fix(source): make cache prop static --- src/source/Source.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/source/Source.ts b/src/source/Source.ts index a1d7966..16e3c3a 100644 --- a/src/source/Source.ts +++ b/src/source/Source.ts @@ -25,21 +25,17 @@ export abstract class Source { public abstract readonly baseUrl: string; - private readonly sourceResultCache: Cacheable; - - public constructor() { - this.sourceResultCache = new Cacheable({ - primary: new Keyv({ store: new CacheableMemory({ lruSize: 1024, ttl: this.ttl }) }), - secondary: new Keyv(new KeyvSqlite(`sqlite://${getCacheDir()}/webstreamr-source-cache.sqlite`)), - }); - } + private static readonly sourceResultCache = new Cacheable({ + primary: new Keyv({ store: new CacheableMemory({ lruSize: 1024 }) }), + secondary: new Keyv(new KeyvSqlite(`sqlite://${getCacheDir()}/webstreamr-source-cache.sqlite`)), + }); protected abstract handleInternal(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])>; public async handle(ctx: Context, type: ContentType, id: Id): Promise<(SourceResult[])> { const cacheKey = `${this.id}_${id.toString()}`; - let sourceResults = (await this.sourceResultCache.get(cacheKey)) + let sourceResults = (await Source.sourceResultCache.get(cacheKey)) ?.map(sourceResult => ({ ...sourceResult, url: new URL(sourceResult.url) })); if (!sourceResults) { @@ -53,7 +49,7 @@ export abstract class Source { } } - await this.sourceResultCache.set(cacheKey, sourceResults); + await Source.sourceResultCache.set(cacheKey, sourceResults, this.ttl); } return sourceResults.filter(sourceResult => sourceResult.countryCode in ctx.config);