我在实体框架中使用缓存。在 for 循环中,我打了 linq 查询 5 次。第一次缓存为空,所以我使用以下缓存策略将其存储在缓存中
else if (cachedData == null)
{
cachedData = this._db.ListsofItems
.Include(a => aItems)
.ToList();
// Save to cache
cache.Set(cacheName, cachedData, new CacheItemPolicy()
{
UpdateCallback = new CacheEntryUpdateCallback(CacheUpdateOnExpiration),
AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddSeconds(50))
});
但是当我第二次点击查询时(这次缓存数据不为空)它返回查询数据。在以下方法中,当我尝试查找计数时,它会自动调用 dispose 方法。不知道为什么。
using (var queries = new Queries(this.Context))
{
m.Started = queries.Get().Filter(itemstatus: new List<int> { 1.2}, stDate: c.AddMonths(-1), eDate: current, limit: 2000).Count();
}
所以问题是,在第二次执行中,为什么 count 会自动调用 dispose 方法?谢谢