Class PropCache<TKey, TValue>
Caches the result of a computation, and invalidates based on ComputeContext invalidation rules. This class allows you to cache the result of a function from TKey to TValue, where the function observes values using a ComputeContext. When the ComputeContext is invalidated, the cache entry will be cleared, and any downstream observers will be invalidated as well.
Note that this cache currently invalidates values only when the ComputeContext is invalidated; in particular, if TKey is a unity object which is destroyed, this in itself will not result in the associated value being freed from memory.
This class is not thread-safe; all calls must be made from the Unity main thread. (This may change in the future)
public sealed class PropCache<TKey, TValue>
Type Parameters
TKeyTValue
- Inheritance
-
PropCache<TKey, TValue>
- Inherited Members
Constructors
PropCache(string, Func<ComputeContext, TKey, TValue>, Func<TValue, TValue, bool>?, IEqualityComparer<TKey>?)
public PropCache(string debugName, Func<ComputeContext, TKey, TValue> operatorFunc, Func<TValue, TValue, bool>? equalityComparer = null, IEqualityComparer<TKey>? keyComparer = null)
Parameters
debugNamestringoperatorFuncFunc<ComputeContext, TKey, TValue>equalityComparerFunc<TValue, TValue, bool>keyComparerIEqualityComparer<TKey>
Methods
Get(ComputeContext, TKey)
Fetches a value from the cache, computing it if necessary.
public TValue Get(ComputeContext context, TKey key)
Parameters
contextComputeContextThe compute context to use to observe the value
keyTKeyThe key to look up
Returns
- TValue
The computed value
InvalidateAll()
public void InvalidateAll()