Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD: caching aggregate objects that received from sever

Suppose I have a repository (ContactsRepository) with method like getAllContacts(userId). The (ContactsRepository) fetch all data from server. After first call getAllContacts(userId) method I want to cache this data. My question is where I should realize caching mechanism, in the same (ContactsRepository) and when I invoke getAllContacts(userId) method again the repository back my caching data or I need put the data into another place (maybe Repository).

like image 398
tikhop Avatar asked Oct 31 '12 10:10

tikhop


1 Answers

You can use Repository to obtain the data either from the cache or from the database. if your Repository classes have update methods you can effectively invalidate the cache items as well.

You can thus encapsulate the access to cache within the Repository: http://martinfowler.com/eaaCatalog/repository.html

Another example to implement caching for Repository: http://ardalis.com/building-a-cachedrepository-via-strategy-pattern

like image 127
coder_bro Avatar answered Sep 30 '22 15:09

coder_bro