# PagingLiveData

Added in 3.0.0

*** ** * ** ***


```
public final class PagingLiveData
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingLiveData#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.Lifecycle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Lifecycle lifecycle )` Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within the scope of a `https://developer.android.com/reference/androidx/lifecycle/Lifecycle`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingLiveData#(androidx.lifecycle.LiveData).cachedIn(kotlinx.coroutines.CoroutineScope)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html scope )` Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingLiveData#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.ViewModel)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull T>> receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModel viewModel )` Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within the scope of a `https://developer.android.com/reference/androidx/lifecycle/ViewModel`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LiveData<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/PagingData<@https://developer.android.com/reference/androidx/annotation/NonNull Value>>` | `<Key extends https://developer.android.com/reference/java/lang/Object.html, Value extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingLiveData#(androidx.paging.Pager).getLiveData()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/paging/Pager<@https://developer.android.com/reference/androidx/annotation/NonNull Key, @https://developer.android.com/reference/androidx/annotation/NonNull Value> receiver )` A `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData`, which mirrors the stream provided by `https://developer.android.com/reference/androidx/paging/Pager#flow()`, but exposes it as a `https://developer.android.com/reference/androidx/lifecycle/LiveData`. |

## Public methods

### cachedIn

Artifact: [androidx.paging:paging-runtime](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingLiveData.kt+function:cachedIn) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull Lifecycle lifecycle
)
```

Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within the scope of a `https://developer.android.com/reference/androidx/lifecycle/Lifecycle`.

`https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.Lifecycle)` multicasts pages loaded and transformed by a `https://developer.android.com/reference/androidx/paging/PagingData`, allowing multiple observers on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.Lifecycle)` is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` emitted by `https://developer.android.com/reference/androidx/paging/Pager` or any of its transformed derivatives, as reloading data from scratch on the same generation of `https://developer.android.com/reference/androidx/paging/PagingData` is an unsupported operation.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Lifecycle lifecycle` | The `https://developer.android.com/reference/androidx/lifecycle/Lifecycle` where the page cache will be kept alive. |

### cachedIn

Artifact: [androidx.paging:paging-runtime](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingLiveData.kt+function:cachedIn) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull CoroutineScope scope
)
```

Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html`.

`https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(kotlinx.coroutines.CoroutineScope)` multicasts pages loaded and transformed by a `https://developer.android.com/reference/androidx/paging/PagingData`, allowing multiple observers on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(kotlinx.coroutines.CoroutineScope)` is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` emitted by `https://developer.android.com/reference/androidx/paging/Pager` or any of its transformed derivatives, as reloading data from scratch on the same generation of `https://developer.android.com/reference/androidx/paging/PagingData` is an unsupported operation.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html scope` | The `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` where the page cache will be kept alive. Typically this would be a managed scope such as `ViewModel.viewModelScope`, which automatically cancels after the `https://developer.android.com/reference/androidx/paging/PagingData` stream is no longer needed. Otherwise, the provided `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` must be manually cancelled to avoid memory leaks. |

### cachedIn

Artifact: [androidx.paging:paging-runtime](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingLiveData.kt+function:cachedIn) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull LiveData<@NonNull PagingData<@NonNull T>> <T extends Object> cachedIn(
    @NonNull LiveData<@NonNull PagingData<@NonNull T>> receiver,
    @NonNull ViewModel viewModel
)
```

Operator which caches a `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData` within the scope of a `https://developer.android.com/reference/androidx/lifecycle/ViewModel`.

`https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.ViewModel)` multicasts pages loaded and transformed by a `https://developer.android.com/reference/androidx/paging/PagingData`, allowing multiple observers on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` to receive the same events, avoiding redundant work, but comes at the cost of buffering those pages in memory.

Calling `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.ViewModel)` is required to allow calling androidx.paging.AsyncPagingDataAdapter on the same instance of `https://developer.android.com/reference/androidx/paging/PagingData` emitted by `https://developer.android.com/reference/androidx/paging/Pager` or any of its transformed derivatives, as reloading data from scratch on the same generation of `https://developer.android.com/reference/androidx/paging/PagingData` is an unsupported operation.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModel viewModel` | The `https://developer.android.com/reference/androidx/lifecycle/ViewModel` whose `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.lifecycle.ViewModel).viewModelScope()` will dictate how long the page cache will be kept alive. |

### getLiveData

Artifact: [androidx.paging:paging-runtime](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingLiveData.kt+symbol:liveData) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public static final @NonNull LiveData<@NonNull PagingData<@NonNull Value>> <Key extends Object, Value extends Object> getLiveData(
    @NonNull Pager<@NonNull Key, @NonNull Value> receiver
)
```

A `https://developer.android.com/reference/androidx/lifecycle/LiveData` of `https://developer.android.com/reference/androidx/paging/PagingData`, which mirrors the stream provided by `https://developer.android.com/reference/androidx/paging/Pager#flow()`, but exposes it as a `https://developer.android.com/reference/androidx/lifecycle/LiveData`.

NOTE: Instances of `https://developer.android.com/reference/androidx/paging/PagingData` emitted by this `https://developer.android.com/reference/androidx/lifecycle/LiveData` are not re-usable and cannot be submitted multiple times. This is especially relevant because `https://developer.android.com/reference/androidx/lifecycle/LiveData` will replays the latest value downstream. To ensure you get a new instance of `https://developer.android.com/reference/androidx/paging/PagingData` for each downstream observer, you should use the `https://developer.android.com/reference/androidx/paging/package-summary#(androidx.lifecycle.LiveData).cachedIn(androidx.lifecycle.Lifecycle)` operator which multicasts the `https://developer.android.com/reference/androidx/lifecycle/LiveData` in a way that returns a new instance of `https://developer.android.com/reference/androidx/paging/PagingData` with cached data pre-loaded.