找出版本缓存里的 bug

来自 API 版本管理
Node 24 进阶 4分钟 找出 1处问题

找出这段生成缓存包装器中的版本隔离缺陷。

JavaScript
function serve(headers, cache) {
  const version = headers["x-api-version"] || "v1";
  const key = "/orders/ord-7";
  if (cache.has(key)) return cache.get(key);

  const body = version === "v1"
    ? { id: "ord-7", total: 25.99 }
    : { id: "ord-7", total: { amount: "25.99", currency: "USD" } };
  cache.set(key, body);
  return body;
}
在试验场中打开
报告错误