Is rxjava cache () the same as replay ()?

I want to know if there is a cache () operator that can cache x emissions, but it will also expire after a specified time interval (for example, 1 minute) I'm looking for something like

Observable<ImmutableList<MyType>> cachedList = otherObservable
    .cache(1,1,TimeUnit.MINUTES);

This caches an item, but expires in a minute and clears the cache

I did some research and found the replay operator It seems that this will meet this need, but I have some problems Why is it hot and needs to be connected? Is this different from the cache () operator? I know the cache () emulation topic, but I don't need a connection

Solution

Caching and replay are for different use cases Caching is an automatic connection replay - all containers usually used for long-term replay Replay can be more parameterized and can be replayed in a limited time / size, but the developer is required to specify when to start The Autoconnect () operator allows you to convert such a connectableobservable instance into a normal observable. Once the user subscribes to it, it connects to the source In this way, you can have a bounded and automatically connected replay (rxjava 1.0.14 required):

source.replay(1,TimeUnit.SECONDS).autoConnect().subscribe(...);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>