From: Michael Tremer Date: Fri, 11 Jul 2025 14:26:07 +0000 (+0000) Subject: frontend: Implement a simple package cache X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd08e6c591bd1a40363c1739d5e84b02dd30f79d;p=pbs.git frontend: Implement a simple package cache This is an experiment, whether this should live in the API or the composable part I don't know, yet. Signed-off-by: Michael Tremer --- diff --git a/frontend/src/api/packages.ts b/frontend/src/api/packages.ts index d4b87cd7..c44b4b9c 100644 --- a/frontend/src/api/packages.ts +++ b/frontend/src/api/packages.ts @@ -106,10 +106,22 @@ export async function fetchPackages(): Promise { return response.data; } +const cachedPackages = new Map(); + // Fetch a package by its UUID export async function fetchPackage(uuid: string): Promise { + let pkg = cachedPackages.get(uuid); + if (pkg) + return pkg; + + // Fetch the package if not cached const response = await api.get(`/v1/packages/${uuid}`); - return response.data; + pkg = response.data as Package; + + // Store this in the cache + cachedPackages.set(pkg.uuid, pkg); + + return pkg; } // Fetch the package filelist