【发布时间】:2013-10-26 00:10:59
【问题描述】:
我们有一个将 C# poco 对象加载到内存中的系统。 (从磁盘上的数据源反序列化)。它们进一步缓存在 ObjectCache (MemoryCache.Default) 中,并通过 Repository 类公开。链条是这样的:
private Dictionary<string, T> itemsDictionary;
private Dictionary<string, T> ItemsDictionary
{
get
{
return itemsDictionary ?? (itemsDictionary = RepositoryLoader.Load());
}
}
private List<T> itemsList;
private List<T> ItemsList
{
get
{
return itemsList ?? (itemsList = ItemsDictionary.Values.ToList());
}
}
public List<T> All { get { return ItemsList; } }
RepositoryLoader.Load() - 这会将内存缓存中的项目缓存为字典...
我的问题是 - 正如您所看到的,它还通过 2 个缓存属性进行 - 它是否会造成内存消耗的重复? :) 有没有办法优化这条链?
【问题讨论】:
-
Values属性已经是ICollection<T>。您可以将其作为属性公开。你有什么理由想要它作为List<T>吗?如果是这样,是什么?也许有更好的方法来解决这个问题。
标签: c# caching properties memorycache