CacheType

Functions for creating and reading a single-flight cache.

Specification

Kind
Type
Members
8
Examples
0
makeSignature
Cache.make lookup
makeBoundedSignature
Cache.makeBounded capacity lookup
makeBoundedWithExpirySignature
Cache.makeBoundedWithExpiry capacity timeToLive lookup
makeRecSignature
Cache.makeRec lookup
getSignature
Cache.get key cache

Summary

NameSignatureSynopsis
Operations
makeCache.make lookupCreates a cache that computes missing values with lookup.
makeBoundedCache.makeBounded capacity lookupCreates a cache retaining at most capacity keys, evicting the least recently read key.
makeBoundedWithExpiryCache.makeBoundedWithExpiry capacity timeToLive lookupCreates an LRU cache whose successful entries expire after timeToLive of monotonic clock time.
makeRecCache.makeRec lookupCreates a cache whose lookup may read other keys through the same cache.
getCache.get key cacheReturns the cached value for a key, or starts its lookup.
invalidateCache.invalidate key cacheForgets a key without interrupting existing waiters.
invalidateAllCache.invalidateAll cacheForgets every cached key.
countCache.count cacheReturns the number of retained keys, including in-flight lookups.

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>

Returns

Flow<'env, 'none, Cache<'key, 'error, 'value>>
kind:member

makeBounded

Cache.makeBounded capacity lookup
Member
Creates a cache retaining at most capacity keys, evicting the least recently read key.

Parameters

NameTypeDescription
capacityint
lookup'key -> Flow<'env, 'error, 'value>

Returns

Flow<'env, 'none, Cache<'key, 'error, 'value>>
kind:member

makeBoundedWithExpiry

Cache.makeBoundedWithExpiry capacity timeToLive lookup
Member
Creates an LRU cache whose successful entries expire after timeToLive of monotonic clock time.

Parameters

NameTypeDescription
capacityint
timeToLiveTimeSpan
lookup'key -> Flow<'env, 'error, 'value>

Returns

Flow<'env, 'none, Cache<'key, 'error, 'value>>
kind:member

makeRec

Cache.makeRec lookup
Member
Creates a cache whose lookup may read other keys through the same cache.

Parameters

NameTypeDescription
lookupCache<'key, 'error, 'value> -> 'key -> Flow<'env, 'error, 'value>

Returns

Flow<'env, 'none, Cache<'key, 'error, 'value>>
kind:member

get

Cache.get key cache
Member
Returns the cached value for a key, or starts its lookup.

Parameters

NameTypeDescription
key'key
cacheCache<'key, 'error, 'value>

Returns

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

invalidate

Cache.invalidate key cache
Member
Forgets a key without interrupting existing waiters.

Parameters

NameTypeDescription
key'key
cacheCache<'key, 'error, 'value>

Returns

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

invalidateAll

Cache.invalidateAll cache
Member
Forgets every cached key.

Parameters

NameTypeDescription
cacheCache<'key, 'error, 'value>

Returns

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

count

Cache.count cache
Member
Returns the number of retained keys, including in-flight lookups.

Parameters

NameTypeDescription
cacheCache<'key, 'error, 'value>

Returns

Flow<'env, 'none, int>