Show / Hide Table of Contents

Class WeakMemoizationCacheFactory

Memoization cache factory for memoization caches that do not keep cache keys alive.

Inheritance
System.Object
WeakMemoizationCacheFactory
Namespace: System.Memory
Assembly: Nuqleon.Memory.dll
Syntax
public static class WeakMemoizationCacheFactory : 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 IWeakMemoizationCacheFactory Nop { get; }
Property Value
Type Description
IWeakMemoizationCacheFactory

Unbounded

Gets a memoization cache factory for weak memoization caches with unbounded storage.

Declaration
public static IWeakMemoizationCacheFactory Unbounded { get; }
Property Value
Type Description
IWeakMemoizationCacheFactory
Remarks

Memoization caches can be cleared explicitly through the MemoizedDelegate<TDelegate> returned from MemoizeWeak methods.

Methods

CreateEvictedByHighest<TMetric>(Func<IMemoizationCacheEntryMetrics, TMetric>, Int32, Double, IStopwatchFactory)

Creates a memoization cache factory for weak 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 IWeakMemoizationCacheFactory 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
IWeakMemoizationCacheFactory

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 weak 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 IWeakMemoizationCacheFactory 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
IWeakMemoizationCacheFactory

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 weak memoization caches that use an LRU cache eviction strategy.

Declaration
public static IWeakMemoizationCacheFactory CreateLru(int maxCapacity)
Parameters
Type Name Description
System.Int32 maxCapacity

The maximum capacity of memoization caches returned by the factory.

Returns
Type Description
IWeakMemoizationCacheFactory

Memoization cache factory for memoization caches that use an LRU cache eviction strategy.

In This Article
Back to top Generated by DocFX