From 3bf25fe8b7a435f81206e573c01b47933001b024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Tue, 14 May 2024 12:13:37 +0200 Subject: [PATCH] Remove blob/tree/stats API cache This is now done properly in radicle-httpd via cache-control headers. --- httpd-client/lib/project.ts | 27 --------------------------- package-lock.json | 9 --------- package.json | 1 - 3 files changed, 37 deletions(-) diff --git a/httpd-client/lib/project.ts b/httpd-client/lib/project.ts index 584d8b496..f7e6eafd8 100644 --- a/httpd-client/lib/project.ts +++ b/httpd-client/lib/project.ts @@ -1,4 +1,3 @@ -import { LRUCache } from "lru-cache"; import type { Commit, Commits } from "./project/commit.js"; import type { Embed } from "./project/comment.js"; import type { Fetcher, RequestOptions } from "./fetcher.js"; @@ -147,14 +146,6 @@ export type ProjectListQuery = { export class Client { #fetcher: Fetcher; - // We make the cache a static variable because clients are usually not - // persisted and new instances are frequently created. - static #cache = { - tree: new LRUCache({ max: 300 }), - stats: new LRUCache({ max: 300 }), - blob: new LRUCache({ max: 500 }), - }; - public constructor(fetcher: Fetcher) { this.#fetcher = fetcher; } @@ -234,11 +225,6 @@ export class Client { path: string, options?: RequestOptions, ): Promise { - const cacheKey = `blob:${sha}:${path}`; - const cachedBlob = Client.#cache.blob.get(cacheKey); - if (cachedBlob) { - return cachedBlob; - } const blob = await this.#fetcher.fetchOk( { method: "GET", @@ -247,7 +233,6 @@ export class Client { }, blobSchema, ); - Client.#cache.blob.set(cacheKey, blob); return blob; } @@ -257,11 +242,6 @@ export class Client { path?: string, options?: RequestOptions, ): Promise { - const cacheKey = `tree:${sha}:${path}`; - const cachedTree = Client.#cache.tree.get(cacheKey); - if (cachedTree) { - return cachedTree; - } const tree = await this.#fetcher.fetchOk( { method: "GET", @@ -270,7 +250,6 @@ export class Client { }, treeSchema, ); - Client.#cache.tree.set(cacheKey, tree); return tree; } @@ -279,11 +258,6 @@ export class Client { sha: string, options?: RequestOptions, ): Promise { - const cacheKey = `tree:stats:${sha}`; - const cachedTree = Client.#cache.stats.get(cacheKey); - if (cachedTree) { - return cachedTree; - } const tree = await this.#fetcher.fetchOk( { method: "GET", @@ -292,7 +266,6 @@ export class Client { }, treeStatsSchema, ); - Client.#cache.stats.set(cacheKey, tree); return tree; } diff --git a/package-lock.json b/package-lock.json index f702e4987..b90764ec8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,6 @@ "hast-util-to-dom": "^4.0.0", "hast-util-to-html": "^9.0.0", "lodash": "^4.17.21", - "lru-cache": "^10.2.0", "marked": "^12.0.1", "marked-katex-extension": "^5.0.1", "marked-linkify-it": "^3.1.9", @@ -3316,14 +3315,6 @@ "get-func-name": "^2.0.1" } }, - "node_modules/lru-cache": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", - "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==", - "engines": { - "node": "14 || >=16.14" - } - }, "node_modules/magic-string": { "version": "0.30.8", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.8.tgz", diff --git a/package.json b/package.json index 2bfd66f67..ba06e9560 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "hast-util-to-dom": "^4.0.0", "hast-util-to-html": "^9.0.0", "lodash": "^4.17.21", - "lru-cache": "^10.2.0", "marked": "^12.0.1", "marked-katex-extension": "^5.0.1", "marked-linkify-it": "^3.1.9",