In a web service, when we put the responsibility of holding data to repositories, should we also put the responsibility of caching to them? Or it's responsibility of another part?
Also, what about the situations when we use in-memory storages as a helper? for example when we counting number of posts' visits per day and saving them eventually in database, Should it handle on Repository?
I think the decorator pattern works well for cached repository. The main idea is to separate caching and storage logic. So it will be correspond to Single responsibility principle.

What about statistic helper, it depends on the context. It can be:
decorator, pass requests through itself, and implements IRepository interface:repo = new StatHelper(new CacheRepo(new DbRepo))
IRepository as a dependency.CacheRepository so as not to inflate the number of classesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With