javascript - Angular 8 - 使用 PublishReplay 缓存 HTTP 请求
问题描述
我现在可以在同一个组件中同时缓存 1 到 2 个 http 请求,并在缓存过期后重新缓存它,但是当我尝试在服务中再添加 1 个 publishReplay() 时,当我导航到其他组件并返回时,它冻结了几秒钟,在它返回之前。
getAllUsers(): Observable<any> {
if (this.reuse) {
return this.reuse;
} else {
return this.reuse = this.http.get(`${environment.url.userProfile}account-info`, this.userprofileKey()).pipe(
publishReplay(1, 20000),
refCount(),
take(1)
);
}
}
enter getUserInterests(): Observable<any> {
if (this.reuse3) {
return this.reuse3;
} else {
return this.reuse3 = this.http.get(`${environment.url.userProfile}interest`, this.userprofileKey()).pipe(
publishReplay(1, 20000),
refCount(),
take(1)
);
}
}
getEntitlementPlan(): Observable<any> {
if (this.reuse2) {
return this.reuse2;
} else {
return this.reuse2 = this.http.get(`${environment.url.entitlement}bau/subscription/current`, this.paymentKey()).pipe(
publishReplay(1, 20000),
refCount(),
take(1)
);
}
}
如果我从上面删除 1 publishReplay()。它工作顺利。
解决方案
推荐阅读
- javascript - AWS cognito 注册和登录 - 如何存储池和应用程序 ID
- node.js - 如何将 Amazon-Alexa 技能连接到 Lambda 和 dynamoDB
- c# - 找出有限区域内字符的最大像素大小
- sql - Postgres中基于多行比较操作更新表列
- ios - 如何使用 swiftUI 在圆形按钮内居中文本?
- drupal-8 - Drupal 8 自定义 Cron 任务
- javascript - 如何在基于功能的反应组件中传递道具和其他参数?
- semantic-release - 使用语义发布获取下一个标签版本
- xml - 如何在 XSLT 中聚合值?
- reactjs - TestCafé + React JSX 错误(意外的令牌)