0

I would like to set up a cache by having a service hold a reference to a BehaviorSubject which will call an API endpoint initially and then emit that result. The tricky thing for me is figuring out how to set a TTL so that if XX seconds has elapsed it recalls the API endpoint instead of returning the last result.

Is this possible with RxJS, or would I need to set up my own timers to 'reset' the BehaviorSubject?

BeaverusIV
  • 988
  • 1
  • 11
  • 26
  • 1
    Have a look at this http://stackoverflow.com/documentation/rxjs/8247/common-recipes/26490/caching-http-responses#t=201703302006007086247 It's using `ReplaySubject` internally but you should get the point behind it and be able to use it for your usecase. – martin Mar 30 '17 at 20:06
  • Thanks, that is perfect, I guess Documentation doesn't show up in the Ask Question search, nor Google search atm. Add this as an answer and I'll accept. – BeaverusIV Mar 30 '17 at 20:10

0 Answers0