@header(' cache-control')在Nestjs中
我有一个Nestjs REST API,并注意到没有发送高速控制标头。我不确定我是否错过了Nestjs的某些内容,但询问Google如何缓存REST API与Nestjs获得响应只会导致我进入内存Cachig中服务器上的Nestjs Cache Manager。 因此,我有两个问题:
- 缓存REST API数据响应
- 我是否应该设置@header('cache-control','..?')可能不是普遍的
- ,也许最好在客户端上缓存? (我知道数据有效性 - 数据没有改变我在谈论文章)
感谢您的答案
I have an NestJS REST api and noticed that Cache-Control header is not sent. I am not sure if i miss something with nestjs but asking google how to cache REST API get response with nestjs only leads me to NestJs cache manager which is on server in memory cachig.
So I have couple of questions:
- Is it not common to cache REST API data responses
- Should I set @Header('Cache-Control', '..?') explicitly
- Maybe it is better to cache on the client? (I know about data validity - data is not changing I am talking about articles)
Thanks for the answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您可以使用标头注释设置它:
https://docs.nestjs.com/controllers#headers
btw。在其余的定义中,应该是可缓存的,不是每种方法:
https://en.wikipedia.org/wikipedia.org/wiki/wiki/representational_state_state_state_state_state_state_state_state_state_transfertansfer#cacheaeaeaeaeaeability
Yes you can set it with the header annotation:
https://docs.nestjs.com/controllers#headers
btw. its in the rest definition that the should be cachable, just not every method:
https://en.wikipedia.org/wiki/Representational_state_transfer#Cacheability