Class Cache<K, V>
Provides fixed size, pre-allocated, least recently used replacement cache.
NOpenNLP: upstream extends java.util.LinkedHashMap and overrides its
removeEldestEntry hook to bound the size. J2N's
J2N.Collections.Generic.OrderedDictionary<TKey, TValue> preserves insertion order but
has no such hook, so the eviction is performed explicitly on insert.
Note that upstream constructs the map in insertion-order mode (not access-order), so the eviction policy is really first-in-first-out; that behavior is preserved here.
public class Cache<K, V> : OrderedDictionary<K, V?>, IDictionary<K, V?>, IReadOnlyDictionary<K, V?>, IDictionary, IList<KeyValuePair<K, V?>>, ICollection<KeyValuePair<K, V?>>, IReadOnlyList<KeyValuePair<K, V?>>, IReadOnlyCollection<KeyValuePair<K, V?>>, IEnumerable<KeyValuePair<K, V?>>, IList, ICollection, IEnumerable, IStructuralEquatable, IFormattable
Type Parameters
KV
- Inheritance
-
OrderedDictionary<K, V>Cache<K, V>
- Implements
-
IDictionary<K, V>IReadOnlyDictionary<K, V>IList<KeyValuePair<K, V>>ICollection<KeyValuePair<K, V>>IReadOnlyList<KeyValuePair<K, V>>IReadOnlyCollection<KeyValuePair<K, V>>IEnumerable<KeyValuePair<K, V>>
- Inherited Members
-
OrderedDictionary<K, V>.AsReadOnly()OrderedDictionary<K, V>.Add(K, V)OrderedDictionary<K, V>.TryAdd(K, V)OrderedDictionary<K, V>.Clear()OrderedDictionary<K, V>.ContainsKey(K)OrderedDictionary<K, V>.ContainsValue(V)OrderedDictionary<K, V>.IndexOf(K)OrderedDictionary<K, V>.Remove(K)OrderedDictionary<K, V>.Remove(K, out V)OrderedDictionary<K, V>.TrimExcess()OrderedDictionary<K, V>.TryGetValue(K, out V)OrderedDictionary<K, V>.GetEnumerator()OrderedDictionary<K, V>.GetAlternateLookup<TAlternateKey>()OrderedDictionary<K, V>.TryGetAlternateLookup<TAlternateKey>(out OrderedDictionary<K, V>.AlternateLookup<TAlternateKey>)OrderedDictionary<K, V>.GetSpanAlternateLookup<TAlternateKeySpan>()OrderedDictionary<K, V>.TryGetSpanAlternateLookup<TAlternateKeySpan>(out OrderedDictionary<K, V>.SpanAlternateLookup<TAlternateKeySpan>)OrderedDictionary<K, V>.GetHashCode()OrderedDictionary<K, V>.ToString()OrderedDictionary<K, V>.CapacityOrderedDictionary<K, V>.EqualityComparerOrderedDictionary<K, V>.CountOrderedDictionary<K, V>.KeysOrderedDictionary<K, V>.ValuesOrderedDictionary<K, V>.this[K]
Constructors
Cache(int)
Provides fixed size, pre-allocated, least recently used replacement cache.
NOpenNLP: upstream extends java.util.LinkedHashMap and overrides its
removeEldestEntry hook to bound the size. J2N's
J2N.Collections.Generic.OrderedDictionary<TKey, TValue> preserves insertion order but
has no such hook, so the eviction is performed explicitly on insert.
Note that upstream constructs the map in insertion-order mode (not access-order), so the eviction policy is really first-in-first-out; that behavior is preserved here.
public Cache(int capacity)
Parameters
capacityint
Properties
this[K]
public V? this[K key] { get; set; }
Parameters
keyK
Property Value
- V
Methods
Add(K, V)
public void Add(K key, V value)
Parameters
keyKvalueV
ComputeIfAbsent(K, Func<K, V>)
public V? ComputeIfAbsent(K key, Func<K, V> func)
Parameters
keyKfuncFunc<K, V>
Returns
- V
Put(K, V)
NOpenNLP: an instance method that takes precedence over the
Put extension method on IDictionary<TKey, TValue>,
which would otherwise assign through the interface indexer and bypass
the eviction above.
public V? Put(K key, V value)
Parameters
keyKvalueV
Returns
- V