InvalidateSetsForNonQuery drops all cached data for the entire table

Jul 14, 2015 at 11:46 AM
it just drops all cached data for the entire table, even if it was a simple one row update.
In my case, it makes EFCaching almost useless.

Why not detect simple one-row update queries like
UPDATE [dbo].[orders]\r\nSET [subject] = @0\r\nWHERE ([order_id] = @1)\r\n
, and in this case invalidate only one item in cache ([order_id] = @1) ?

I'm now trying to implement this functionality in my project, but the question is - why this was not implemented out of the box? I don't think this is generally a good idea to drop cache all the time.

Are there some potential problems?

Thanks in advance!
Jul 14, 2015 at 8:07 PM
EF Cache works on the level where it does not have enough data to tell which entry in the cache should be invalidated so it is invalidating all entries that have any results that came from a table being modified. Parsing back SQL is not an option since it would be unreliable - especially for the gargantuan queries EF creates if you map hierarchies, wouldn't work on different platforms, etc. On the other hand - caching all the results blindly does not make sense in my opinion. Instead you should look at patterns used in your app and cache results only where it makes sense (e.g. for tables where the data is not being updated frequently).