0

I have created a sample project in .NET Core 3 using NuGet package Microsoft.Extensions.Caching.StackExchangeRedis for distributed caching. Everything is working fine but I am not sure what would happen if multiple clients asynchronously and concurrently used some particular resource.

I am not able to find any new articles/solutions regarding the concurrent access and therefore using some mechanism for locking. There are many old articles but nothing that has been posted lately so I am not sure to what extend those solutions work years after their release.

Are locks necessary for asynchronous access and concurrent use of resources in .NET Core using Microsoft.Extensions.Caching.StackExchangeRedis package? If that's the case - some help (code/articles/links) would be much appreciated.

BlazK
  • 43
  • 7
  • With access you mean... reading/obtaining the value? Writing? – Tseng Sep 01 '20 at 10:44
  • Well anything that could lead to issues. I guess the major issue is with writing yes. – BlazK Sep 02 '20 at 11:03
  • 1
    More context please. And why is that an issue? Redis is for caching, not for storage. In worst case, you have slightly outdated or inconsistent data until the cache expires by which time you'd need to fetch the value anyways and put it in there. If you have multiple instances being hit and getting cache miss, they most likely having the same data. Cache should be fairly short-lived, to reduce database or external service hits. In general eventual consistency is good enough for caching scenarios. For more advanced scenarios you may not want direct updates to the cache and use invalidation – Tseng Sep 02 '20 at 11:10
  • Check this [question](https://stackoverflow.com/questions/64219151/distributed-lock-is-not-working-with-redlock-net) – Matt Qafouri Sep 09 '21 at 05:33

0 Answers0