gpt4 book ai didi

javascript - Angular2 缓存 HTTP 响应的最简单方法

转载 作者:数据小太阳 更新时间:2023-10-29 05:54:15 26 4
gpt4 key购买 nike

<分区>

我有一个页面向同一位置发出 http 请求,只是根据用户的需要使用不同的参数。所以我的代码看起来像这样:

this.http.post( //I am open to POST methods or GET methods as I have security in the back to prevent malicious writes.
'http://192.168.1.45:3000/mylocation',
'p1=' + param1 + '&p2=' + param2,
{headers: headers}
)

例如,在 JQuery 中,您已经在框架中构建了一个缓存属性,它可以自动缓存并且非常容易实现:

$.ajax({
cache: true,
//other options...
});

Angular2 有类似的东西吗?只要用户在应用程序中,我就想缓存这些动态响应。因此,如果用户请求具有相同参数的相同 url,那么它只会从缓存中获取它,如果参数从未被使用过,那么它会进行网络调用。

我在请求选项的 Angular2 文档中找不到任何内容:

https://angular.io/docs/js/latest/api/http/RequestOptions-class.html

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