Class MemoizationCacheFactory
Memoization cache factory for memoization caches that are not thread-safe.
Inheritance
Namespace: System.Memory
Assembly: Nuqleon.Memory.dll
Syntax
public static class MemoizationCacheFactory : Object
Properties
Nop
Gets a memoization cache factory for memoization caches without any storage. This allows to disable memoization while retaining a code structure that relies on IMemoizationCacheFactory instances.
Declaration
public static IMemoizationCacheFactory Nop { get; }
Property Value
Type | Description |
---|---|
IMemoizationCacheFactory |
Unbounded
Gets a memoization cache factory for memoization caches with unbounded storage.
Declaration
public static IMemoizationCacheFactory Unbounded { get; }
Property Value
Type | Description |
---|---|
IMemoizationCacheFactory |
Remarks
Memoization caches can be cleared explicitly through the System.Memory.MemoizedDelegate`1 returned from Memoize methods.
Methods
CreateEvictedByHighest<TMetric>(Func<IMemoizationCacheEntryMetrics, TMetric>, Int32, Double, IStopwatchFactory)
Creates a memoization cache factory for memoization caches that use an eviction strategy based on a function to rank cache entries based on metrics. Entries that meet the age threshold and have the highest score as computed by the ranker get evicted.
Declaration
public static IMemoizationCacheFactory CreateEvictedByHighest<TMetric>(Func<IMemoizationCacheEntryMetrics, TMetric> ranker, int maxCapacity, double ageThreshold = 0.9, IStopwatchFactory stopwatchFactory = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IMemoizationCacheEntryMetrics, TMetric> | ranker | The ranker function used to obtain the metric for each entry upon evicting entries from the cache. |
System.Int32 | maxCapacity | The maximum capacity of memoization caches returned by the factory. |
System.Double | ageThreshold | The threshold used to decide whether an entry has aged sufficiently in order to be considered for eviction. E.g. a value of 0.9 means that the youngest 10% of entries cannot get evicted. |
IStopwatchFactory | stopwatchFactory | The stopwatch factory used to create stopwatches that measure access times and function invocation times. If omitted, the default stopwatch is used. |
Returns
Type | Description |
---|---|
IMemoizationCacheFactory | Memoization cache factory for memoization caches that use a ranking-based cache eviction strategy. |
Type Parameters
Name | Description |
---|---|
TMetric | Type of the metric to rank cache entries by. |
CreateEvictedByLowest<TMetric>(Func<IMemoizationCacheEntryMetrics, TMetric>, Int32, Double, IStopwatchFactory)
Creates a memoization cache factory for memoization caches that use an eviction strategy based on a function to rank cache entries based on metrics. Entries that meet the age threshold and have the lowest score as computed by the ranker get evicted.
Declaration
public static IMemoizationCacheFactory CreateEvictedByLowest<TMetric>(Func<IMemoizationCacheEntryMetrics, TMetric> ranker, int maxCapacity, double ageThreshold = 0.9, IStopwatchFactory stopwatchFactory = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IMemoizationCacheEntryMetrics, TMetric> | ranker | The ranker function used to obtain the metric for each entry upon evicting entries from the cache. |
System.Int32 | maxCapacity | The maximum capacity of memoization caches returned by the factory. |
System.Double | ageThreshold | The threshold used to decide whether an entry has aged sufficiently in order to be considered for eviction. E.g. a value of 0.9 means that the youngest 10% of entries cannot get evicted. |
IStopwatchFactory | stopwatchFactory | The stopwatch factory used to create stopwatches that measure access times and function invocation times. If omitted, the default stopwatch is used. |
Returns
Type | Description |
---|---|
IMemoizationCacheFactory | Memoization cache factory for memoization caches that use a ranking-based cache eviction strategy. |
Type Parameters
Name | Description |
---|---|
TMetric | Type of the metric to rank cache entries by. |
CreateLru(Int32)
Creates a memoization cache factory for memoization caches that use an LRU cache eviction strategy.
Declaration
public static IMemoizationCacheFactory CreateLru(int maxCapacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxCapacity | The maximum capacity of memoization caches returned by the factory. |
Returns
Type | Description |
---|---|
IMemoizationCacheFactory | Memoization cache factory for memoization caches that use an LRU cache eviction strategy. |