Closed LeedsCode closed 5 years ago
Have you tried adding Cacheable()
before the ToList()
method?
That fixed it perfectly, actually!
Before:
public override IEnumerable<LineItem> Get(Expression<Func<LineItem, bool>> filter = null, params Expression<Func<LineItem, object>>[] include)
{
IQueryable<LineItem> query = _dbSet;
query = query.Cacheable(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(5));
if (filter != null)
query = query.Where(filter);
if (include != null)
{
foreach (var includeProperty in include.ToList())
query = query.Include(includeProperty);
}
return query.ToList();
}
That didn't work. This worked as expected:
public override IEnumerable<LineItem> Get(Expression<Func<LineItem, bool>> filter = null, params Expression<Func<LineItem, object>>[] include)
{
IQueryable<LineItem> query = _dbSet;
if (filter != null)
query = query.Where(filter);
if (include != null)
{
foreach (var includeProperty in include.ToList())
query = query.Include(includeProperty);
}
query = query.Cacheable(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(5));
return query.ToList();
}
The issue can be closed, but I guess I'm not sure why the call need to be done after the rest of it. Without looking in to the code, I would expect that either of the above methods would work the same. Maybe I'll be able to look at it sometime, but is it easy to make it work either way? I would assume the Cacheable call must overwrite the ToList() method if there's a matching cached version. A fix would be to overwrite the ToList() method by default to check the status of some new property like CachedValue. I'm just kind of guessing how it works at this point, tho.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.
Summary of the issue
If you call the same query but only change the include, the cached value is used, ignoring the different include.
Environment
Example code/Steps to reproduce:
Output: