Header menu logo TDesu.FSharp

Memoize Module

Thread-safe memoization with optional TTL.

On .NET uses ConcurrentDictionary{TKey,TValue}. On Fable uses plain Dictionary (JS is single-threaded). TTL variants periodically clean up stale entries every 1000 operations.

Functions and values

Function or value Description

Memoize.create f

Full Usage: Memoize.create f

Parameters:
    f : 'TKey -> 'TValue

Returns: 'TKey -> 'TValue

Memoizes a function. Cached forever (or until process restart). Function whose results are cached by input key.

f : 'TKey -> 'TValue
Returns: 'TKey -> 'TValue

Memoize.createAsync f

Full Usage: Memoize.createAsync f

Parameters:
    f : 'TKey -> Task<'TValue>

Returns: 'TKey -> Task<'TValue>

Memoizes an async function. Cached forever. Under contention, f may execute more than once per key; only the last result is kept. Async function whose results are cached by input key.

f : 'TKey -> Task<'TValue>
Returns: 'TKey -> Task<'TValue>

Memoize.withTtl ttl f

Full Usage: Memoize.withTtl ttl f

Parameters:
Returns: 'TKey -> 'TValue

Memoizes a function with time-to-live. Expired entries are recomputed. Stale entries are periodically cleaned up to prevent unbounded memory growth. Duration before a cached entry expires. Function whose results are cached by input key.

ttl : TimeSpan
f : 'TKey -> 'TValue
Returns: 'TKey -> 'TValue

Memoize.withTtlAsync ttl f

Full Usage: Memoize.withTtlAsync ttl f

Parameters:
Returns: 'TKey -> Task<'TValue>

Memoizes an async function with time-to-live. Stale entries are periodically cleaned up to prevent unbounded memory growth. Duration before a cached entry expires. Async function whose results are cached by input key.

ttl : TimeSpan
f : 'TKey -> Task<'TValue>
Returns: 'TKey -> Task<'TValue>

Type something to start searching.