存储库模式-缓存 [英] Repository Pattern - Caching

查看:57
本文介绍了存储库模式-缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定应该在我的存储库模式中在哪里实现缓存。

I'm not sure where I should implement the caching in my repository pattern.

我应该在服务逻辑中还是在存储库中实现它?

Should I implement it in the service-logic or in the repository?


GUI-> BusinessLogic(服务)-> DataAccess(存储库)

GUI -> BusinessLogic (Services) -> DataAccess (Repositories)


推荐答案

我将在存储库/数据访问层中对其进行处理。原因是因为它不取决于从何处获取数据的业务层,即存储库的工作。然后,存储库将根据数据访问逻辑的情况,决定从何处,从缓存(如果不是太旧)或实时数据源中获取数据。

I would handle it in the repository/data access layer. The reasoning is because it isn't up to the business layer on where to get the data from, that is the job of the repository. The repository will then decide where to get the data from, the cache (if it's not too old) or from the live data source based on the circumstances of the data access logic.

对数据访问的关注不仅仅是业务逻辑问题。

It's a data access concern more than a business logic issue.

这篇关于存储库模式-缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆