Skip to content

Commit 6e2f7b0

Browse files
committed
fix key loopup
1 parent a9614f5 commit 6e2f7b0

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/core/src/cache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ for (const type of ["memory", "jsonl", "fs"]) {
4646
assert.ok(sha)
4747
assert.strictEqual(typeof sha, "string")
4848
})
49-
test("getOrUpdate retrieves existing value", async () => {
49+
test(`${type} getOrUpdate retrieves existing value`, async () => {
5050
const cache = createCache<string, number>("testCache", {
5151
type: type as any,
5252
})

packages/core/src/memcache.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class MemoryCache<K, V>
6464
validator?: (val: V) => boolean
6565
): Promise<{ key: string; value: V; cached?: boolean }> {
6666
await this.initialize()
67-
const sha = await hash(key)
67+
const sha = await this.getSha(key)
6868
if (this._entries[sha]) {
6969
this.dbg(`getup ${sha}: hit`)
7070
return { key: sha, value: this._entries[sha].val, cached: true }
@@ -101,7 +101,8 @@ export class MemoryCache<K, V>
101101
const sha = await this.getSha(key)
102102
const ent = { sha, val } satisfies CacheEntry<V>
103103
const ex = this._entries[sha]
104-
if (ex && JSON.stringify(ex) == JSON.stringify(ent)) return // No change
104+
if (ex !== undefined && JSON.stringify(ex) == JSON.stringify(ent))
105+
return // No change
105106

106107
this._entries[sha] = ent
107108
await this.appendEntry(ent)

0 commit comments

Comments
 (0)