v2.4.0
What's changed
- Provide two new time-based expiry schemes for
ConcurrentLru
:- Expire after access: evict after a fixed duration since an entry's most recent read or write. This is equivalent to MemoryCache's sliding expiry, and is useful for data bound to a session that expires due to inactivity.
- Per item expiry time: evict after a duration calculated for each item using the specified
IExpiryCalculator
. Expiry time may be set independently at creation, after a read and after a write.
- Align
TryRemove
overloads withConcurrentDictionary
forIAsyncCache
andAsyncAtomicFactory
, matching the implementation forICache
added in v2.3.0. This adds two new overloads:bool TryRemove(K key, out V value)
- enables getting the value that was removed.bool TryRemove(KeyValuePair<K, V> item)
- enables removing an item only when the key and value are the same.
- Add extension methods to make it more convenient to use
AsyncAtomicFactory
with a plainConcurrentDictionary
. This is similar to storing anAsyncLazy<T>
instead ofT
, but with the same exception propagation semantics and API asConcurrentDictionary.GetOrAdd
. - BitFaster.Caching assembly marked as trim compatible to enable trimming when used in native AOT applications.
AtomicFactory
value initialization logic modified to mitigate lock convoys, based on the approach given here.- Fixed
ConcurrentLru.Clear
to correctly handle removed items present in the internal bookkeeping data structures.
Full changelog: v2.3.3...v2.4.0