Skip to content

Instantly share code, notes, and snippets.

Created Aug 17, 2021
What would you like to do?
evict on update example
class TodoRepository(
private val localSource: ITodoCache, // Cache injection
private val remoteSource: ITodoApi
) {
// new resource to query List<Todo>
private val todoResource: Resource<Unit, List<Todo>>
// call evict after every resource update attempt
suspend fun addTodo(todo: Todo): Boolean? =
remoteSource.addTodo(todo).also { resourceGroup.evict() }
suspend fun deleteTodo(todo: Todo): Boolean? =
remoteSource.deleteTodo(todo).also { resourceGroup.evict() }
suspend fun updateTodo(todo: Todo, update: Todo): Boolean? =
remoteSource.updateTodo(todo, update).also { resourceGroup.evict() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment