[go: nahoru, domu]

Add Flow<PagedData<T>>.cached

This CL adds caching to Paging such that any flow of PagedData can
be cached in any layer, making any downstream share the same data.

The given scope keeps the PagedData alive meaning that it must be
cancelled, otherwise, PagedData will live in memory forever.

Since Flow library does not provide sharing functionality yet, this
CL uses a port from Dropbox/Store/Multiplexer. When Multiplexer
starts supporting keepAlive, we should start depending on it.
When Flow implements share, we should try to migrate if possible.

Currently, this CL indefinitely buffers page events. A followup
CL will include an intermediate class to flatten pages so that
we don't keep dropped pages in memory.

Bug: 146677974
Test: CachingTest
Change-Id: I12ae2125599315bf58f5fcde313f3d3611e90671
diff --git a/paging/common/api/current.txt b/paging/common/api/current.txt
index c32e398..d6597dd 100644
--- a/paging/common/api/current.txt
+++ b/paging/common/api/current.txt
@@ -1,6 +1,10 @@
 // Signature format: 3.0
 package androidx.paging {
 
+  public final class CachedPagedDataKt {
+    method public static <T> kotlinx.coroutines.flow.Flow<androidx.paging.PagedData<T>> cachedIn(kotlinx.coroutines.flow.Flow<androidx.paging.PagedData<T>>, kotlinx.coroutines.CoroutineScope scope);
+  }
+
   public abstract class DataSource<Key, Value> {
     method @AnyThread public void addInvalidatedCallback(androidx.paging.DataSource.InvalidatedCallback onInvalidatedCallback);
     method @AnyThread public final void addInvalidatedCallback(kotlin.jvm.functions.Function0<kotlin.Unit> onInvalidatedCallback);
@@ -329,3 +333,10 @@
 
 }
 
+package androidx.paging.multicast {
+
+  public final class ChannelManagerKt {
+  }
+
+}
+