Skip to content

SqliteCacheStore updates an existing cache row without updating the vary column #5108

@trivikr

Description

@trivikr

Bug Description

SqliteCacheStore updates an existing cache row without updating the vary column

Reproducible By

import { cacheStores } from "undici";

const store = new cacheStores.SqliteCacheStore();
const now = Date.now();

// 1. Seed a non-varying entry.
store.set(
  {
    origin: "localhost",
    path: "/",
    method: "GET",
    headers: {},
  },
  {
    statusCode: 200,
    statusMessage: "initial",
    headers: {},
    cachedAt: now,
    staleAt: now + 1000,
    deleteAt: now + 2000,
    body: Buffer.from("initial"),
  },
);

// 2. Overwrite the same URL/method with a varying response.
// This takes the UPDATE path, but sqlite-cache-store.js does not update `vary`.
store.set(
  {
    origin: "localhost",
    path: "/",
    method: "GET",
    headers: {
      "accept-language": "en",
    },
  },
  {
    statusCode: 200,
    statusMessage: "updated",
    headers: {},
    vary: {
      "accept-language": "en",
    },
    cachedAt: now,
    staleAt: now + 1000,
    deleteAt: now + 2000,
    body: Buffer.from("updated"),
  },
);

// 3. This should miss, because the stored response now varies on accept-language.
const result = store.get({
  origin: "localhost",
  path: "/",
  method: "GET",
  headers: {
    "accept-language": "fr",
  },
});

// Expected: undefined
// Actual today: the updated row is returned, because `vary` stayed NULL in SQLite.
console.log(result);

store.close();

Expected Behavior

When an existing cache row is overwritten, the vary column should also be updated.

If a response changes from non-varying to varying, later lookups should only match requests whose headers satisfy the stored vary constraints.

Logs & Screenshots

{
  body: <Buffer 75 70 64 61 74 65 64>,
  statusCode: 200,
  statusMessage: 'updated',
  headers: {},
  etag: undefined,
  vary: undefined,
  cacheControlDirectives: undefined,
  cachedAt: 1777086121760,
  staleAt: 1777086122760,
  deleteAt: 1777086123760
}

Environment

macOS 26.4.1
Node v24.15.0
undici v8.1.0

Metadata

Metadata

Assignees

No one assigned

    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