【问题标题】:How to disable REST API caching如何禁用 REST API 缓存
【发布时间】:2021-06-02 06:00:11
【问题描述】:

我有一个使用 vue.js 为前端构建并部署在 vercel 上的 stat tracker web 应用程序。我还用 express.js 构建了后端并部署在 heroku 上。每当我搜索用户统计信息时,它都会缓存结果。 如何禁用该缓存结果?

前端:

axios.defaults.headers = {
  'Cache-Control': 'no-cache',
  'Pragma': 'no-cache',
  'Expires': '0',
};

后端:

app.use(cors(corsOptions));
app.use(nocache()) //npm library
app.set('etag',false)
app.disable('view cache')

【问题讨论】:

  • 我也注意到了,它只被缓存在 vercel 而不是 localhost 上。

标签: javascript express vue.js caching axios


【解决方案1】:

https://stackoverflow.com/questions/39129932/explicitly-disable-caching-for-rest-services[1] 以某种方式回答了这个问题。您可以实现一个中间件,将Cache-Control: must-revalidate,no-cache,no-store 设置为我们要禁用缓存的所有标头。

【讨论】:

  • nocache() 库已经添加了它们。
猜你喜欢
  • 1970-01-01
  • 2016-11-14
  • 2020-08-19
  • 2021-08-16
  • 2021-10-29
  • 1970-01-01
  • 1970-01-01
  • 2015-04-25
  • 1970-01-01
相关资源
最近更新 更多