Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aleweichandt
Created August 17, 2021 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleweichandt/86bfa654e252e1b70c6a9b775186711a to your computer and use it in GitHub Desktop.
Save aleweichandt/86bfa654e252e1b70c6a9b775186711a to your computer and use it in GitHub Desktop.
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