Skip to content

SqliteCacheStore allows maxCount to overshoot by one entry #5111

@trivikr

Description

@trivikr

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

2

Environment

macOS 26.4.1
Node v24.15.0
undici v8.1.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions