From ed7138cf5f9c4a7e891f2f4afdbc7084fdee6aec Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 27 Sep 2026 17:25:27 +0200 Subject: [PATCH] Task/enable browser cache for logo endpoints (#7956) * Enable browser cache * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/logo/logo.controller.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad28005494..f5431bf8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Simplified the portfolio summary by hiding the currency on mobile +- Improved the performance of the logo endpoints by enabling the browser cache - Improved the language localization for Catalan (`ca`) ### Fixed diff --git a/apps/api/src/app/logo/logo.controller.ts b/apps/api/src/app/logo/logo.controller.ts index 47bd1fc750..30c85e585e 100644 --- a/apps/api/src/app/logo/logo.controller.ts +++ b/apps/api/src/app/logo/logo.controller.ts @@ -11,12 +11,15 @@ import { } from '@nestjs/common'; import { DataSource } from '@prisma/client'; import { Response } from 'express'; +import ms from 'ms'; import { GetLogoDto } from './get-logo.dto'; import { LogoService } from './logo.service'; @Controller('logo') export class LogoController { + private static readonly CACHE_MAX_AGE_IN_SECONDS = ms('7 days') / 1000; + public constructor(private readonly logoService: LogoService) {} @Get(':dataSource/:symbol') @@ -34,6 +37,12 @@ export class LogoController { }); response.contentType(type); + + response.setHeader( + 'Cache-Control', + `public, max-age=${LogoController.CACHE_MAX_AGE_IN_SECONDS}` + ); + response.send(buffer); } catch { response.status(HttpStatus.NOT_FOUND).send(); @@ -49,6 +58,12 @@ export class LogoController { const { buffer, type } = await this.logoService.getLogoByUrl(url); response.contentType(type); + + response.setHeader( + 'Cache-Control', + `public, max-age=${LogoController.CACHE_MAX_AGE_IN_SECONDS}` + ); + response.send(buffer); } catch { response.status(HttpStatus.NOT_FOUND).send();