I was wondering if there was a cache()
operator that could cache x number of emissions but also expire them after a specified time interval (e.g. 1 minute). I was l
cache
and replay
are meant for different use cases. Cache is an auto-connecting replay-everything container used typically for long-term replays. Replay can have more parametrization and can do bounded time/size replays but requires the developer to specify when to start. The autoConnect()
operator lets you turn such ConnectableObservable
instances to a plain Observable
which connects to the source once a subscriber subscribes to them. This way, you can have a bounded and auto-connecting replay (requires RxJava 1.0.14+):
source.replay(1, TimeUnit.SECONDS).autoConnect().subscribe(...);