Search code examples
c#asp.netasp.net-corememorycache

ASP.NET Core MemoryCache - Update item while being used


I can't find any info on how exactly I should update the existing cache items. Do I need to Lock the item before I update it?

What happens if users are iterating over the ListOFStuff cache item and some other task Sets it with new value during the read, what will happen?

cache.Set(“LS”, ListOFStuff);

Solution

  • According to MSDN MemoryCache is Thread safe, so don't have to implement Thread Safety by your own.