CacheModule

Functions for creating and reading a single-flight Cache`3.

Summary

NameSignatureSynopsis
Operations
makeCache.make lookupCreates a cache that computes missing values with lookup.
getCache.get key cacheReturns the value for a key, running the lookup if no success is cached and none is running.
invalidateCache.invalidate key cacheForgets a key's cached value, so the next get runs the lookup again.
invalidateAllCache.invalidateAll cacheForgets every cached value.
countCache.count cacheReturns the number of keys that are cached or being looked up.

Operations

kind:member

make

Cache.make lookup
Member
Creates a cache that computes missing values with lookup.

Parameters

NameTypeDescription
lookup'key -> Flow<'env, 'error, 'value>Computes the value for a key.

Returns

Flow<'env, 'none, Cache<'key, 'error, 'value>>

Verification Examples

flow {
    let! users = Cache.make loadUser
    let! first = users |> Cache.get 42
    let! again = users |> Cache.get 42 // no second load
    return first = again
}
kind:member

get

Cache.get key cache
Member
Returns the value for a key, running the lookup if no success is cached and none is running.

Parameters

NameTypeDescription
key'keyThe key to read.
cacheCache<'key, 'error, 'value>The cache.

Returns

Flow<'env, 'error, 'value>
kind:member

invalidate

Cache.invalidate key cache
Member
Forgets a key's cached value, so the next get runs the lookup again.

Parameters

NameTypeDescription
key'keyThe key to forget.
cacheCache<'key, 'error, 'value>The cache.

Returns

Flow<'env, 'none, unit>
kind:member

invalidateAll

Cache.invalidateAll cache
Member
Forgets every cached value.

Parameters

NameTypeDescription
cacheCache<'key, 'error, 'value>The cache.

Returns

Flow<'env, 'none, unit>
kind:member

count

Cache.count cache
Member
Returns the number of keys that are cached or being looked up.

Parameters

NameTypeDescription
cacheCache<'key, 'error, 'value>The cache.

Returns

Flow<'env, 'none, int>