【问题标题】:Prevent caching for certain API route - ETag?防止缓存某些 API 路由 - ETag?
【发布时间】:2017-12-22 04:15:19
【问题描述】:

我很困惑为什么会得到这个:

GET /api/v1/changelog/json 304 50.967 ms - -

看起来浏览器正在缓存结果...但这是一个 JSON 请求,不应该被缓存。

我想我需要更改标题以便它使用“应用程序/json”标题? 那会阻止缓存吗?

但问题是,我已经有了那个标题:

     getGitLog: function () {
        return $http({
          method: 'GET',
          url: `/api/v1/changelog/json`,
          data: {},
          headers: {
            'Content-Type': 'application/json'
          },
        })
     },

【问题讨论】:

标签: node.js http express http-status-code-304


【解决方案1】:

你可以像这样使用 cache: false 选项:

getGitLog: function () {
    return $http({
      method: 'GET',
      url: `/api/v1/changelog/json`,
      cache: false,
      data: {},
      headers: {
        'Content-Type': 'application/json'
      },
    })
 },

【讨论】:

    【解决方案2】:

    似乎禁用 Etag 是解决方案。使用 Node.js Express,那就是:

    app.disable('etag');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 2020-06-01
      • 2018-05-13
      • 1970-01-01
      • 2019-06-25
      相关资源
      最近更新 更多