javascript - rxjs Observable publishReplay new data -
i'm trying cache user data rxjs , works charm
protected users$ = observable.defer(() => this.getusersuncached()) .publishreplay(1, 5000) .refcount() .take(1); public getusers(): observable<user[]> { this.users$.sharereplay() return this.users$; } public getusersuncached(): observable<user[]> { return this.api.get('/user') .map((response) => response.json().data) .catch(this.handleerror); }
if call getusers cached userdata 5 seconds, , if call getusersuncached data uncached api
what super neat if call getuseruncached reset timer of cache , update it's content. i'm asking there clean method or should build own timer & behaviorsubject?
Comments
Post a Comment