Add does nothing (returns false ) if there is already a value for this key. Set if necessary, inserts or updates.
Remove + Add will leave a gap in the middle when another thread requesting this key does not receive any hint ( Set does not; swap is usually atomic); as such, while Set has the same end result as Remove + Add , the difference in the mechanism is important, as this can affect other callers.
For example Add :
Return value
Type: System.Boolean true if the insert was successful, or false if the cache already has an entry with the same key as the key.
Marc Gravell Jan 15 2018-12-12T00: 00Z
source share