Bug Description
SqliteCacheStore allows maxCount to overshoot by one entry
Reproducible By
import { cacheStores } from "undici";
const store = new cacheStores.SqliteCacheStore({ maxCount: 1 })
store.set(
{ origin: 'localhost', path: '/a', method: 'GET', headers: {} },
{
statusCode: 200,
statusMessage: '',
headers: {},
cachedAt: Date.now(),
staleAt: Date.now() + 1_000,
deleteAt: Date.now() + 10_000,
body: Buffer.from('a')
}
)
store.set(
{ origin: 'localhost', path: '/b', method: 'GET', headers: {} },
{
statusCode: 200,
statusMessage: '',
headers: {},
cachedAt: Date.now(),
staleAt: Date.now() + 1_000,
deleteAt: Date.now() + 10_000,
body: Buffer.from('b')
}
)
console.log(store.size) // 2
Expected Behavior
The cache should enforce maxCount strictly and evict before or during the second insert so that store.size <= maxCount after each write. With maxCount: 1, the second insert should leave exactly one entry.
Logs & Screenshots
Environment
macOS 26.4.1
Node v24.15.0
undici v8.1.0
Bug Description
SqliteCacheStore allows
maxCountto overshoot by one entryReproducible By
Expected Behavior
The cache should enforce
maxCountstrictly and evict before or during the second insert so thatstore.size <= maxCountafter each write. WithmaxCount: 1, the second insert should leave exactly one entry.Logs & Screenshots
Environment
macOS 26.4.1
Node v24.15.0
undici v8.1.0