mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-30 17:14:40 +08:00
fix(kilo-sessions): cache undefined values in in-flight cache
Track entry presence separately from the cached value so `undefined` results are treated as valid cache hits within the TTL.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
type Entry<T> = {
|
||||
at: number
|
||||
value: T | undefined
|
||||
has: boolean
|
||||
inflight: Promise<T> | undefined
|
||||
}
|
||||
|
||||
@@ -11,7 +12,8 @@ export function withInFlightCache<T>(key: string, ttlMs: number, cb: () => Promi
|
||||
const existing = store.get(key) as Entry<T> | undefined
|
||||
|
||||
if (existing) {
|
||||
if (existing.value !== undefined && now - existing.at < ttlMs) return Promise.resolve(existing.value)
|
||||
// Allow caching `undefined` by tracking presence separately.
|
||||
if (existing.has && now - existing.at < ttlMs) return Promise.resolve(existing.value as T)
|
||||
if (existing.inflight && now - existing.at < ttlMs) return existing.inflight
|
||||
}
|
||||
|
||||
@@ -19,16 +21,19 @@ export function withInFlightCache<T>(key: string, ttlMs: number, cb: () => Promi
|
||||
? {
|
||||
at: now,
|
||||
value: existing.value,
|
||||
has: existing.has,
|
||||
inflight: undefined,
|
||||
}
|
||||
: {
|
||||
at: now,
|
||||
value: undefined,
|
||||
has: false,
|
||||
inflight: undefined,
|
||||
}
|
||||
|
||||
const task = cb().then((value) => {
|
||||
next.value = value
|
||||
next.has = true
|
||||
return value
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user