简体   繁体   中英

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).

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

您可以缓存它,但如果您使用多个存储库执行域逻辑,请不要忘记缓存一致性 ,例如在多台计算机上。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM