diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-05 09:24:28 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-08 11:05:14 -0400 |
| commit | 387efac23ffcb5743279ba96798fc5db26ce6807 (patch) | |
| tree | 9a90c1aca537bcc4726f06952015ec151f88b505 /packages/backend/src/server/web | |
| parent | don't proxy local URLs (diff) | |
| download | sharkey-387efac23ffcb5743279ba96798fc5db26ce6807.tar.gz sharkey-387efac23ffcb5743279ba96798fc5db26ce6807.tar.bz2 sharkey-387efac23ffcb5743279ba96798fc5db26ce6807.zip | |
add version specifier to URL preview cache
Diffstat (limited to 'packages/backend/src/server/web')
| -rw-r--r-- | packages/backend/src/server/web/UrlPreviewService.ts | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/backend/src/server/web/UrlPreviewService.ts b/packages/backend/src/server/web/UrlPreviewService.ts index 0312dff16d..fc09554ce8 100644 --- a/packages/backend/src/server/web/UrlPreviewService.ts +++ b/packages/backend/src/server/web/UrlPreviewService.ts @@ -30,6 +30,9 @@ export type LocalSummalyResult = SummalyResult & { haveNoteLocally?: boolean; }; +// Increment this to invalidate cached previews after a major change. +const cacheFormatVersion = 1; + @Injectable() export class UrlPreviewService { private logger: Logger; @@ -119,10 +122,10 @@ export class UrlPreviewService { }; } - const key = `${url}@${lang}`; - const cached = await this.previewCache.get(key); + const cacheKey = `${url}@${lang}@${cacheFormatVersion}`; + const cached = await this.previewCache.get(cacheKey); if (cached !== undefined) { - this.logger.info(`Returning cache preview of ${key}`); + this.logger.info(`Returning cache preview of ${cacheKey}`); // Cache 7days reply.header('Cache-Control', 'max-age=604800, immutable'); @@ -134,8 +137,8 @@ export class UrlPreviewService { } this.logger.info(this.meta.urlPreviewSummaryProxyUrl - ? `(Proxy) Getting preview of ${key} ...` - : `Getting preview of ${key} ...`); + ? `(Proxy) Getting preview of ${cacheKey} ...` + : `Getting preview of ${cacheKey} ...`); try { const summary: LocalSummalyResult = this.meta.urlPreviewSummaryProxyUrl @@ -174,7 +177,7 @@ export class UrlPreviewService { await this.inferActivityPubLink(summary); } - this.previewCache.set(key, summary); + this.previewCache.set(cacheKey, summary); // Cache 7days reply.header('Cache-Control', 'max-age=604800, immutable'); |