MemoryCache

Posted chucklu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MemoryCache相关的知识,希望对你有一定的参考价值。

https://docs.microsoft.com/en-us/dotnet/api/system.runtime.caching.memorycache?view=netframework-4.8

 

What‘s the difference between MemoryCache.Add and MemoryCache.Set?

 

Add does nothing (returns false) if there is already a value for that key. Set does an insert or update, as necessary.

Remove + Add would leave a gap in the middle when another thread querying that key would get no clue (Set does not; the swap is typically atomic); as such, while Set has the same end result as Remove + Add, the mechanism difference is important since it could impact other callers.

For example of Add:

Return Value

Type: System.Boolean true if insertion succeeded, or false if there is an already an entry in the cache that has the same key as key. 

 

以上是关于MemoryCache的主要内容,如果未能解决你的问题,请参考以下文章

MemoryCache获取/设置并分配给变量

.NET Core 2.0迁移技巧之MemoryCache问题修复

#yyds干货盘点#分析一个错误使用MemoryCache导致的BUG

停止 MemoryCache 调用的重入

MemoryCache 使用不当导致的一个 BUG

正确使用 .NET MemoryCache 的锁定模式