We have a large ReadOnlyDictionaryone that serves as a high-speed cache for a large number of data objects with which we need to have quick access.
In the timer, we regularly load the removable cache, and then, when it is fully loaded, we replace the existing cache object with the newly created one, so that operations continue without interruption.
Recently, we have run into memory leak problems, and one of the things we are considering is cache replacement.
A simplified record of what we do:
public class Optimizations
{
private volatile ReadOnlyDictionary<string, Dictionary<string, object>> _cache;
public object GetFromLocalCache(string dataSet, string key)
{
object obj;
Dictionary<string, object> dict;
if (_cache.TryGetValue(dataSet, out dict) && dict.TryGetValue(key, out obj))
{
return obj;
}
return null;
}
private void OnTimerEvent()
{
ReadOnlyDictionary<string, Dictionary<string, object>> newCache = ...
_cache = newCache;
}
}
, , _cache, , , , . - , , , ?