dimanche 22 septembre 2019

How to implement the repository pattern with updatable caches

I'm struggling to apply the repository pattern in a project.

The requirement is not complicated:
1. When a client requests some entity list from a server, the client saves them to a local database for caching. 2. If there is a cache, the client should use them (within expire time). 3. When the client gets user action like refresh data or receives some notification, the client should update local data from a remote server whether they expired or not.

I learned the repository pattern abstract persistence of the domain entity.
So an application doesn't need to know where the entity comes from. (from a server or local database and so on.)

But how can I update local data hidden by repository?
By adding flags in the repository method argument?

fun get(id: EntityId, update: Boolean)

But I think that reveals implementation detail.
Should the repository listen to a domain event like UpdateEntityRequested?

Please help. Thank you.

Aucun commentaire:

Enregistrer un commentaire