-
-
Save aleweichandt/86bfa654e252e1b70c6a9b775186711a to your computer and use it in GitHub Desktop.
evict on update example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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