我正在使用 Azure AppFabric 通过全新的存储库进行缓存。我的存储库看起来像这样:
public interface IMyRepository
{
public IEnumerable<K> Select(IQueryable<T> someQuery)
public IEnumerable<T> SelectAllStudents() // should I replace T with Children in my repository?
}
我的目的是公开并缓存来自客户端的 OData 请求,因此是 IQueryable。我还有一个次要需求是频繁返回如下所示的数据
public class Children
{
public string Name {get;set;}
public int CountOfToys {get;set;}
public List<Toys> {get;set;}
}
但是我的数据库是1..many
的 child 到玩具。
当前的 ASP.NET 应用程序直接在 aspx 页面中使用 EF 的导航属性来填充上面的 ViewModel,但是我不知道将此功能移植到存储库的最有效的路由。
由于 AppFabric 缓存,我对 IEnumerable 结果的限制是:
- 返回的对象不能是值类型
- 返回的对象必须是可序列化的
- How do I implement the IMyRepository to support caching OData queries?
- Is it OK for a repository to emit not only model classes, but the "children" aggregate class? What is the proper term for this?
- Assuming that the step above is Okay, should I use navigation properties to populate this extra class?
最佳答案
缓存存储库实体将更容易控制,这意味着您的系统中有一个内存数据库,但性能和灵 active 较差。缓存域对象可以提高性能,因为它更接近您实际想要缓存的内容。但你需要考虑缓存项之间的同步。我想通过引入单独的缓存管理器组件来在服务层上进行缓存。
关于linq - 可以让存储库与服务层返回 View 或 View 模型吗?哪些应该被缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8131419/