【问题标题】:Cache strategies using IQueryables使用 IQueryables 缓存策略
【发布时间】:2010-11-21 09:37:35
【问题描述】:

我一直在思考如何最好地缓存 IQueryables。我正在使用存储库模式将数据提取到诸如此类的类中:

public class Item
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IQueryable<Category> { get; set; } // For simplicity. It is actually a LazyList<Category> containing an IQueryable
}

现在我将如何最好地缓存这个对象?我想保持可查询的延迟执行,因为实际上除了 Category 之外还有更多可以链接到该项目的东西,我最好不要将它们获取到存储在对象上,因为对象可能会变得太大,或者它们可能需要单独缓存。

我在想Compiled Query 可以以某种方式使这成为可能,我只是不太明白如何。有没有人找到任何好的解决方案?这似乎是一种非常常用的模式。

【问题讨论】:

    标签: linq caching repository-pattern iqueryable


    【解决方案1】:

    使用已编译的查询,您将缓存 Func&lt;MyDataContext, IQueryable&lt;Category&gt;&gt; 类型的结果委托。每当您想要一个新的可查询对象时,您只需创建一个新的数据上下文以传递给委托并像往常一样查询生成的 IQueryable&lt;Category&gt;

    【讨论】:

      猜你喜欢
      • 2010-10-06
      • 2012-09-05
      • 2020-08-03
      • 2011-11-12
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多