Entity framework 使用entity framework和postsharp创建需要缓存的对象模型有哪些选项?
我正在使用一个对性能要求很高的互联网应用程序,这意味着良好的缓存功能对我们的成功至关重要 该解决方案首先使用实体框架代码进行数据库访问,然后使用Postsharp进行缓存。目前,模型如下所示Entity framework 使用entity framework和postsharp创建需要缓存的对象模型有哪些选项?,entity-framework,caching,ef-code-first,postsharp,devforce,Entity Framework,Caching,Ef Code First,Postsharp,Devforce,我正在使用一个对性能要求很高的互联网应用程序,这意味着良好的缓存功能对我们的成功至关重要 该解决方案首先使用实体框架代码进行数据库访问,然后使用Postsharp进行缓存。目前,模型如下所示 public class Article { private readonly IProducerOperator _producerOperator; public Article(IProducerOperator operator) { _producerOperator =
public class Article
{
private readonly IProducerOperator _producerOperator;
public Article(IProducerOperator operator)
{ _producerOperator = operator; }
public int Id { get; set; }
...
public int ProducerId { get; set; }
public Producer Producer {
get { return _producerOperator.GetProducer(ProducerId); }
}
}
public class ArticleOperations : IArticleOperations
{
private readonly IDataContext _context;
public ArticleOperations(IDataContext context)
{ _context = context; }
[Cache]
public Article GetArticle(int id)
{
var article = _context.Article.Find(id);
return article;
}
}
public class ProducerOperations : IProducerOperations
{
private readonly IDataContext _context;
public ProducerOperations(IDataContext context)
{ _context = context; }
[Cache]
public Producer GetProducer(int id)
{
var producer = _context.Producer.Find(id);
return producer;
}
}
操作类如下所示
public class Article
{
private readonly IProducerOperator _producerOperator;
public Article(IProducerOperator operator)
{ _producerOperator = operator; }
public int Id { get; set; }
...
public int ProducerId { get; set; }
public Producer Producer {
get { return _producerOperator.GetProducer(ProducerId); }
}
}
public class ArticleOperations : IArticleOperations
{
private readonly IDataContext _context;
public ArticleOperations(IDataContext context)
{ _context = context; }
[Cache]
public Article GetArticle(int id)
{
var article = _context.Article.Find(id);
return article;
}
}
public class ProducerOperations : IProducerOperations
{
private readonly IDataContext _context;
public ProducerOperations(IDataContext context)
{ _context = context; }
[Cache]
public Producer GetProducer(int id)
{
var producer = _context.Producer.Find(id);
return producer;
}
}
我不喜欢在业务对象中具有依赖性,但其理由是从缓存中进行延迟加载。。。最多。这个解决方案还意味着缓存只对生产者执行一次。。。在GetProducer
。通常我甚至不会考虑在那里有依赖关系。对象应该是POCOs,仅此而已。我真的需要一些新的信息。我该怎么做呢?这是最好的方式吗
我们还需要解决相反的问题,即从缓存的生产者那里,我们应该能够检索其所有文章。首先,我想说的是,实际上有一些(一个?)解决方案首先使用实体框架代码,然后使用postsharp进行缓存。Ideablades首先发布了Devforce代码,实际上就是这样做的。这种框架实际上解决了所有问题,我们可以按照预期使用实体框架,并与缓存结合使用 但这并没有成为本案的解决方案。我们选择了完全分离关注点,这意味着业务对象唯一关注点将只包含数据。操作类负责填充业务对象