采用我所判断的最好办法,在http://www.yoda.arachsys.com/csharp/singleton.html”上“rel=“nofollow” 在C#执行单一吨位模式令人惊讶的文章中,我成功地利用了以下类别来保存用户界定的数据(关于很少修改的数据):
public class Params
{
static readonly Params Instance = new Params();
Params()
{
}
public static Params InMemory
{
get
{
return Instance;
}
}
private IEnumerable<Localization> _localizations;
public IEnumerable<Localization> Localizations
{
get
{
return _localizations ?? (_localizations = new Repository<Localization>().Get());
}
}
public int ChunkSize
{
get
{
// Loc uses the Localizations impl
LC.Loc("params.chunksize").To<int>();
}
}
public void RebuildLocalizations()
{
_localizations = null;
}
// other similar values coming from the DB and staying in-memory,
// and their refresh methods
}
我的用意是这样:
var allLocs = Params.InMemory.Localizations; //etc
电话 我更新了该数据库,重新启用了Refresh Localizations,因此,仅重置了我内部储存的一部分。 在大约10个见
我目前对单一州持怀疑态度,我认为这项工作非常艰巨,所有单位测试都证明,单一州机制、复习机制和援助团的业绩都是预期的。
尽管如此,我还是看着这些可能性:
- This customer is lying when he says their environment is not using loading balance, which is a setting I am not expecting the in-memory stuff to work properly (right?)
- There is some non-standard pool configuration in their IIS which I am testing against (maybe in a Web Garden setting?)
- The singleton is failing somehow, but not sure how.
任何建议?
<>strong>NET 3.5, 如此之不相平行,现在还不准备使用追溯式延长。
Edit1:根据建议,新老会看像:
public IEnumerable<Localization> Localizations
{
get
{
lock(_localizations) {
return _localizations ?? (_localizations = new Repository<Localization>().Get());
}
}
}