gpt4 book ai didi

javascript - 获取缓存响应 - 无缓存 header 未按预期工作

转载 作者:行者123 更新时间:2023-12-05 04:09:47 26 4
gpt4 key购买 nike

我一直在做 random quote machine freecodecamp 的项目,我似乎无法阻止正在缓存的 api 的响应。

我试过各种答案:

我以为我曾经有过它:

fetch(this.url, {cache: 'no-cache'})
.then(res => res.json())

...但我只是在开发者工具中禁用了缓存。

请帮忙。 :-D.

这是我一直在努力让它发挥作用的地方: https://codepen.io/JonathanDWood/pen/gRNNKx

最佳答案

我已经设法通过将 Date.now() 附加到 url 来修复它。我不太喜欢将它作为永久解决方案,因为它没有解决潜在的缓存问题,但它确实有效。

fetch(this.url+ Date.now(), {cache: 'no-store'})
.then(res => res.json())

关于javascript - 获取缓存响应 - 无缓存 header 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com