【问题标题】:DDD: caching aggregate objects that received from severDDD:缓存从服务器接收到的聚合对象
【发布时间】:2012-10-20 18:49:12
【问题描述】:

假设我有一个存储库(ContactsRepository),其方法类似于getAllContacts(userId)(ContactsRepository) 从服务器获取所有数据。在第一次调用getAllContacts(userId) 方法后,我想缓存这些数据。我的问题是我应该在哪里实现缓存机制,在同一个(ContactsRepository) 中,当我再次调用getAllContacts(userId) 方法时,存储库会返回我的缓存数据,或者我需要将数据放到另一个地方(可能是存储库)。

【问题讨论】:

    标签: oop design-patterns architecture domain-driven-design


    【解决方案1】:

    您可以使用 Repository 从缓存或数据库中获取数据。如果您的 Repository 类具有更新方法,您也可以有效地使缓存项无效。

    因此,您可以将对缓存的访问封装在存储库中: http://martinfowler.com/eaaCatalog/repository.html

    另一个为 Repository 实现缓存的例子: http://ardalis.com/building-a-cachedrepository-via-strategy-pattern

    【讨论】:

    • 谢谢你的回答,我已经意识到就像在你的第二个链接中一样。
    【解决方案2】:

    你可以缓存它,但不要忘记cache coherency 如果你使用多个存储库执行域逻辑,例如在多台机器上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多