I need to implement pull to refresh in an iOS app, and I came across this thing, in where I don't know how to approach the problem with the best practices of DDD.
The presentation layer has an event to refresh a list, this needs to update the results throwing away the cache and fetching the elements from the backend.
In the Domain layer, my use case talks to a repository, but, since caching is an implementation detail, the repository interface does not expose a 'cleanCache' method, so there is no clean way to refresh cache from a use case. this is more or less the file structure that I have
Domain
- GetAllTodosUseCase
- TodosRepository (interface)
Infrastructure
- InMemoryTodosRepository (cache)
- RemoteTodosRepository (api)
- InMemoryWithRemoteTodosRepository (composes cache and api)
Application
- factories
Presentation
- UI (talks to an interactor interface)
Since it seems to be use case specific when it is okay use a cache and when the remote resources need to be fetched, the decision which repository to use best fits to the application layer.
You could use, for instance, a factory which provides the application use cases the concrete repository implementations at runtime, still being dependent on the repository interface only at compile time.
Or you create another repository interface with the same methods and explicitly bind this repository interface to the concrete use case which should use the cache.