【发布时间】:2015-02-08 01:25:48
【问题描述】:
我有这样的缓存服务:
public interface ICacheService {
T Get<T>(string cacheID, Func<T> getItemCallback, int cacheMinutes = 5) where T : class;
}
public class MemoryCacheService : ICacheService {
public T Get<T>(string cacheId, Func<T> getItemCallback, int cacheMinutes = 5) where T : class {
T item = MemoryCache.Default.Get(cacheId) as T;
if (item == null) {
item = getItemCallback();
MemoryCache.Default.Add(cacheId, item,
new CacheItemPolicy {AbsoluteExpiration = DateTime.Now.AddMinutes(cacheMinutes)});
}
return item;
}
}
并像这样检索:
var result = _cache.Get("mylist", () => _database.Fetch<MyList>().AsQueryable(), 600);
该列表很大,并且在每次击键预先输入下拉列表中经常访问。而且查询条件也是动态的,比如
if (this) result = result.Where(x=> this ...)
if (that) result = result.Where(x=> that ...)
finally result.ToList()
我想知道,每次我从缓存中访问列表时,系统是否会在开始构建 linq 查询之前创建数据副本?如果是这样,这就像每次击键复制一样,效率不高。还是它推迟了查询,因为我正在检索 AsQueryable 并构建 linq?
还有更好的选择吗?谢谢
【问题讨论】:
标签: c# linq memorycache