Closed MoienTajik closed 5 years ago
True. It doesn't see anything after the Cacheable()
method. For these cases (FirstOrDefaultAsync
/ SingleOrDefaultAsync()
), add a Where()
method before the .Cacheable()
method:
var ad = context.Analytics.Cacheable().FirstOrDefault(x => x.ID == 5);
// change it to
var ac = context.Analytics.Where(x => x.ID == 5).Cacheable().FirstOrDefault();
This could be better at least by writing a Roslyn Analyzer for queries which are using Cacheable
to get a warning/error at compile time. I can write that and open a pull request if you're ok with it.
Fixed it via #https://github.com/VahidN/EFSecondLevelCache.Core/commit/17a44e4da90fed372cfd12e7d797683793120d8a. Now it sees the whole expression tree.
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
When an argument passes to the
FirstOrDefaultAsync
method ( and this issue may exist for other methods likeToListAsync
,SingleAsync
, ... ), theCacheable
caches the results correctly, but when another argument with different value passes to it, it returns the previous results again.Seems like the
Cacheable
method only differs and watch for different argument values just in theWhere
clause, not theFirstOrDefaultAsync
,SingleOrDefaultAsync
and other EntityFramework.Core methods, because different argument values work correctly by usingWhere
method.I know that the
Cacheable
is written on top ofIQueryable
and it caches the result based on theQuery
, but with that, we're unable to use the Microsoft.EntityFramework.Core queryable extensions anymore.Environment
Example code/Steps to reproduce: