]> git.ipfire.org Git - pbs.git/commitdiff
frontend: Implement a simple package cache
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 Jul 2025 14:26:07 +0000 (14:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 Jul 2025 14:26:07 +0000 (14:26 +0000)
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 <michael.tremer@ipfire.org>
frontend/src/api/packages.ts

index d4b87cd7df3f0ff7e4db7506b9948b0929a7166e..c44b4b9cc1bce00cde98b5cf5b173d248f0221c9 100644 (file)
@@ -106,10 +106,22 @@ export async function fetchPackages(): Promise<PackageSummary[]> {
        return response.data;
 }
 
+const cachedPackages = new Map<string, Package>();
+
 // Fetch a package by its UUID
 export async function fetchPackage(uuid: string): Promise<Package> {
+       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