Using what I rated was the best of all worlds on Implementing the Singleton Template in C # , a terrific article, I successfully use the following class to store user data in memory (for very rarely modified data):
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
{
LC.Loc("params.chunksize").To<int>();
}
}
public void RebuildLocalizations()
{
_localizations = null;
}
}
My usage would look something like this:
var allLocs = Params.InMemory.Localizations;
Whenever I update the database, RefreshLocalizations is called, so only part of my storage in memory is restored. I have one out of 10 production environment that seems to behave badly when RefreshLocalizations is called rather than refreshing at all, but it also seems choppy and very strange in general.
, , , , , singleton, RAM .
, :
- , , , , , (?).
- IIS , (, Web Garden?)
- - , , .
?
.NET 3.5, , Reactive Extensions
Edit1: :
public IEnumerable<Localization> Localizations
{
get
{
lock(_localizations) {
return _localizations ?? (_localizations = new Repository<Localization>().Get());
}
}
}