For the needs of my app, I need to share some data access logic between a
Service
and a
Worker
. For that matter I introduced a
Repository
. Because the service needs to know when data from the repository have changed, the repository exposes data as
Flow<List<Foo>>
(making it a reactive repository).
Since database access can be expensive i'd like to introduce some memory cache so that either the
Service
or the
Worker
can query the current
List<Foo>
faster.
Where would you put that cache ?
1. As a field in the repository itself.
2. As a field in a decorator that wraps the
Repository
.
3. In the
Service
, by consuming the flow with
broadcastIn
.
4. You wouldn't use a memory cache, as
Room
loads fast enough.