Remove blob/tree/stats API cache

This is now done properly in radicle-httpd via cache-control headers.
This commit is contained in:
Rūdolfs Ošiņš
2024-05-14 12:13:37 +02:00
parent 521ccd0928
commit 3bf25fe8b7
3 changed files with 0 additions and 37 deletions
-27
View File
@@ -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<string, Tree>({ max: 300 }),
stats: new LRUCache<string, TreeStats>({ max: 300 }),
blob: new LRUCache<string, Blob>({ max: 500 }),
};
public constructor(fetcher: Fetcher) {
this.#fetcher = fetcher;
}
@@ -234,11 +225,6 @@ export class Client {
path: string,
options?: RequestOptions,
): Promise<Blob> {
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<Tree> {
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<TreeStats> {
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;
}
-9
View File
@@ -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",
-1
View File
@@ -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",