RxJava- Is cache() the same as replay()?

丶灬走出姿态 提交于 2019-11-30 06:41:23

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(...);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!