MemoryCache Thread Safety, Is Locking Necessary?

前端 未结 7 576
你的背包
你的背包 2020-12-07 18:34

For starters let me just throw it out there that I know the code below is not thread safe (correction: might be). What I am struggling with is finding an implementation that

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 18:42

    The default MS-provided MemoryCache is entirely thread safe. Any custom implementation that derives from MemoryCache may not be thread safe. If you're using plain MemoryCache out of the box, it is thread safe. Browse the source code of my open source distributed caching solution to see how I use it (MemCache.cs):

    https://github.com/haneytron/dache/blob/master/Dache.CacheHost/Storage/MemCache.cs

提交回复
热议问题