Angular 新鲜度策略也从缓存中获取数据

Angular freshness strategy fetches data also from cache

在 Angular 文档上,service worker freshness 策略描述如下:

freshness optimizes for currency of data, preferentially fetching requested data from the network. Only if the network times out, according to timeout, does the request fall back to the cache. This is useful for resources that change frequently; for example, account balances.

我在我的解决方案中实施了这个策略:

// ngsw-config.json

"dataGroups": [{
    "name": "jokes-cache",
    "urls": [ "https://icanhazdadjoke.com/" ],
    "cacheConfig": {
      "strategy": "performance",
      "maxSize": 5,
      "maxAge": "1d"
    }
  },
  {
    "name": "stocks-cache",
    "urls": [ "https://api.worldtradingdata.com/api/v1/stock" ],
    "cacheConfig": {
      "strategy": "freshness",
      "maxSize": 10,
      "maxAge": "1d",
      "timeout": "5s"
    }
  }]

但是当我查看 DevTools 的网络选项卡时,我可以看到不仅触发了网络调用,而且还访问了本地缓存:

我希望只看到 "stock" 端点的网络调用,并且无法访问缓存(响应在 5 秒超时之前出现)。

屏幕截图看起来正确。第二个请求附近的齿轮图标并不意味着访问缓存 - 它只是意味着这个网络请求是从 service worker 执行的(在这种情况下是预期的行为)。