Skip to content

Conversation

@bitfaster
Copy link
Owner

@bitfaster bitfaster commented Sep 9, 2023

Provide functional parity with ConcurrentDictionary for ICache.TryRemove.

  • Provide bool TryRemove(K key, out V value) and bool TryRemove(KeyValuePair<K,V> item)
  • Underneath, use ConcurrentDictionary TryRemove(key, out value) for ICache TryRemove(K key) and TryRemove(K key, out V value) to avoid double dictionary lookup then remove.
  • Use the old method of retrieve, check, then atomic delete for TryRemove(KeyValuePair<K,V>)
  • ICache default implementations for backwards compatibility throw NotSupportedException. There is no way to correctly implement either new method, so it is better to throw than give the caller an incorrect result. This would only apply if a caller implements ICache themselves, upgrades the library, and doesn't have impls for these methods.
  • Atomics implement IEquatable to compare wrapped values. Values that are not yet created are always not equal, similar to comparing null.
  • AsyncAtomic family can follow a similar pattern, but this is not implemented in this PR.
  • Defer support for scoped caches, less clear how to implement this.

@coveralls
Copy link

coveralls commented Sep 9, 2023

Coverage Status

coverage: 97.182% (+0.009%) from 97.173% when pulling cc1e338 on users/alexpeck/tryrem into a112f23 on main.

@bitfaster bitfaster changed the title Align TryRemove overloads with ConcurrentDictionary Align ICache.TryRemove overloads with ConcurrentDictionary Sep 9, 2023
@bitfaster bitfaster marked this pull request as ready for review September 11, 2023 22:19
@bitfaster bitfaster merged commit 2f120e0 into main Sep 12, 2023
@bitfaster bitfaster deleted the users/alexpeck/tryrem branch September 12, 2023 03:51
bitfaster added a commit that referenced this pull request Nov 13, 2023
Provide functional parity with ConcurrentDictionary for IAsyncCache.TryRemove, following the implementation for ICache in PR #394.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add TryRemove(KeyValuePair<K, V>) overload [Feature request] Add TryRemove(K, out V) overload

3 participants