I am trying to figure out which layer should be responsible for the caching (insert/remove) work in a Domain Driven Design project. The goal is to improve performance of the Web Application by caching any entities that is retrieved from the repository.
My solution is separated as follows:
MyApp.Infrastracture
MyApp.Repositories
MyApp.Domain
MyApp.WebApplication
I feel that since it’s only the Web Application that utilises the cache then it should be this layer that the caching logic should go? However this does not feel correct as i want to keep the web app lightweight and focused on serving web pages.
Also caching is not a first class domain concept so does not have a natural fit in the Domain layer.
What to do?
It is a concern of all of the above.
Caching is one of those cross cutting concerns that each layer needs to handle individually and the application needs to orchestrate.