From 805b59092e7efaab37053dc1898e5fb1a435636f Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Fri, 19 Jun 2026 16:29:52 -0500 Subject: [PATCH] Remove duplicate key check in cacheCommandOutput and related tests This key-check is unnecessary because this function is only ever called if the key does NOT exist in the cache already. In that case, why check again? --- lib/entry-points.js | 5 ----- src/cache.test.ts | 16 ---------------- src/cache.ts | 9 --------- 3 files changed, 30 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 965223138..07b48863f 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -149942,11 +149942,6 @@ function writeCommandCacheFile(data) { } } function cacheCommandOutput(key, cmd, output) { - if (inMemoryCache.has(key)) { - throw new Error( - `cacheCommandOutput() should be called only once per key, but was called more than once for '${key}'.` - ); - } const entry = { cmd, output }; inMemoryCache.set(key, entry); const data = readCommandCacheFile(); diff --git a/src/cache.test.ts b/src/cache.test.ts index 6f9757e03..c76e4719f 100644 --- a/src/cache.test.ts +++ b/src/cache.test.ts @@ -216,19 +216,3 @@ test.serial( }); }, ); - -test.serial( - "cacheCommandOutput throws if called twice for the same key", - async (t) => { - await withCacheDir(() => { - cacheCommandOutput(CommandCacheKey.Version, "/path/to/codeql", { - value: 1, - }); - t.throws(() => - cacheCommandOutput(CommandCacheKey.Version, "/path/to/codeql", { - value: 2, - }), - ); - }); - }, -); diff --git a/src/cache.ts b/src/cache.ts index f9f3afb6e..660a0eb9c 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -79,21 +79,12 @@ function writeCommandCacheFile(data: Record): void { /** * Stores the output of a command under `key`, writing it to both the in-memory * memo (tier 1) and the temporary file (tier 2). - * - * Should only be called once per key within a single process; doing otherwise - * indicates a logic error, since a value that has already been cached should be - * served from the memo rather than recomputed. */ export function cacheCommandOutput( key: CommandCacheKey, cmd: string, output: unknown, ): void { - if (inMemoryCache.has(key)) { - throw new Error( - `cacheCommandOutput() should be called only once per key, but was called more than once for '${key}'.`, - ); - } const entry: CommandCacheEntry = { cmd, output }; inMemoryCache.set(key, entry);