其他分享
首页 > 其他分享> > MemoryCache

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. 

 

标签:already,false,MemoryCache,Add,does,key,Set
来源: https://www.cnblogs.com/chucklu/p/10767353.html