如何在Linq的实现缓存到SQL?

问题描述:

我们刚刚开始使用LINQ to SQL在我们DAL和放大器的工作;我们还没有真正想出了缓存模型的标准。 previously,我们使用的是基础,实现我们所有的DAL类继承自一个高速缓存管理器属性DAL级已之中,但现在我们没有这样的。我想知道,如果有人想出了一个标准的方法来缓存LINQ to SQL的结果?

We've just started using LINQ to SQL at work for our DAL & we haven't really come up with a standard for out caching model. Previously we had being using a base 'DAL' class that implemented a cache manager property that all our DAL classes inherited from, but now we don't have that. I'm wondering if anyone has come up with a 'standard' approach to caching LINQ to SQL results?

我们正在努力在网络环境中(IIS)如果有差别。我知道这很可能最终会被href="http://*.com/questions/tagged/subjective" rel="nofollow">主观问题上

We're working in a web environment (IIS) if that makes a difference. I know this may well end up being a subjective question, but I still think the info would be valuable.

编辑::要澄清一下,我不是在谈论缓存单个结果,我经过的架构解决方案是,如你如何设置缓存,以便所有的链接方法使用相同的缓存架构。

To clarify, I'm not talking about caching an individual result, I'm after more of an architecture solution, as in how do you set up caching so that all your link methods use the same caching architecture.

一个快速的回答:使用存储库模式(见领域驱动设计埃文斯),以获取你的实体。每个库将缓存的东西会持有,最好通过让的存储库访问的每个实例的单例缓存(每个线程/请求都会实例化一个新的存储库,但只能有一个高速缓存)。

A quick answer: Use the Repository pattern (see Domain Driven Design by Evans) to fetch your entities. Each repository will cache the things it will hold, ideally by letting each instance of the repository access a singleton cache (each thread/request will instantiate a new repository but there can be only one cache).

以上回答适用于只有一台机器。为了能够使用这个在很多机器上,使用 memcached的作为缓存解决方案。祝你好运!

The above answer works on one machine only. To be able to use this on many machines, use memcached as your caching solution. Good luck!