Class WeakCache<TKey, TValue>
A cache that maps keys to values for as long as neither the key nor the value of a key-value pair is garbage-collected. Weak caches do not prevent keys or values from being garbage-collected.
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Flame.Collections
Assembly: Flame.dll
Syntax
public sealed class WeakCache<TKey, TValue> : Cache<TKey, TValue> where TKey : class where TValue : class
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Remarks
Public instance methods of this class are thread-safe.
Constructors
| Improve this Doc View SourceWeakCache()
Creates a weak cache.
Declaration
public WeakCache()
WeakCache(IEqualityComparer<TKey>)
Creates a weak cache that uses a particular key comparer under the hood.
Declaration
public WeakCache(IEqualityComparer<TKey> keyComparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<TKey> | keyComparer | A key comparer. |
WeakCache(IEqualityComparer<TKey>, Int32)
Creates a weak cache that uses a particular key comparer under the hood and can be accessed by up to maxConcurrency threads simultaneously (under ideal circumstances).
Declaration
public WeakCache(IEqualityComparer<TKey> keyComparer, int maxConcurrency)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<TKey> | keyComparer | A key comparer. |
System.Int32 | maxConcurrency | The maximum number of threads that can access the weak cache simultaneously under optimal circumstances. |
Methods
| Improve this Doc View SourceCleanup()
Explictly cleans up all outdated keys in the weak cache.
Declaration
public void Cleanup()
Get(TKey, Func<TKey, TValue>)
Declaration
public override TValue Get(TKey key, Func<TKey, TValue> createValue)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Func<TKey, TValue> | createValue |
Returns
Type | Description |
---|---|
TValue |
Overrides
Flame.Collections.Cache<TKey, TValue>.Get(TKey, System.Func<TKey, TValue>)
|
Improve this Doc
View Source
Insert(TKey, TValue)
Declaration
public override sealed void Insert(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | value |
Overrides
Flame.Collections.Cache<TKey, TValue>.Insert(TKey, TValue)
|
Improve this Doc
View Source
TryGet(TKey, out TValue)
Declaration
public override sealed bool TryGet(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
TValue | value |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Flame.Collections.Cache<TKey, TValue>.TryGet(TKey, TValue)