1

I am using Memory cache to retreive object. However if I modify property its automatically updated in cache without calling MemoryCache.Set. Btw we are talking about Asp.Net Core IMemoryCache.

I have issue which is kinda strange. I retreive object from database and set it to cache. It has property Childrens. If I navigate in Blazor to children page and then move back somehow parent's property Childrens is changed. Only code where I am setting "= ..." property is while creating memory object. Then I just using simple Childrens.Where. Solution to this would be getting object from Memory Cache which is not automatically updated when Blazor do some stuff to my object.

wychmaster
  • 712
  • 2
  • 8
  • 23
user1085907
  • 1,009
  • 2
  • 16
  • 40
  • Weird. Definitely netcore issue. Removing AsNoTracking resolved issue – user1085907 Apr 28 '20 at 09:23
  • https://stackoverflow.com/questions/129389/how-do-you-do-a-deep-copy-of-an-object-in-net – Hans Passant Apr 28 '20 at 13:50
  • @HansPassant wow thanks. However I thought for something already implemented. Anyway thanks for solution for deep copy – user1085907 Apr 28 '20 at 17:56
  • I had this issue too it's not related to AsNoTracking, opened an issue: https://github.com/dotnet/aspnetcore/issues/21405 – Zulander May 01 '20 at 18:39
  • @Zulander sad there is not copy but ref :/ – user1085907 May 01 '20 at 20:43
  • This totally breaks internal use of `ConcurrentDictionary` for cached entries and the consistency of the items.. imagine that someone accidentally updates the object property and the other person reads the dirty item.. or both work on that same item at that same time! – Gumowy Kaczak Sep 28 '20 at 10:01
  • @GumowyKaczak my intentions is not to work with cached items like "updates". My intention is just to read faster than loading it from db. While during editing I am loading it freshly from DB – user1085907 Sep 28 '20 at 12:08

0 Answers0