CacheType

Cache

Specification

Kind
Type
Members
9
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
Create caches
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.
Access values
getCache.get key cacheReturns the cached value for a key, or starts its lookup.
countCache.count cacheReturns the number of retained keys, including in-flight lookups.
Invalidate values
invalidateCache.invalidate key cacheForgets a key without interrupting existing waiters.
invalidateAllCache.invalidateAll cacheForgets every cached key.
Operations
getSureCache.getSure key cacheReturns the cached value for a key in a cache whose lookup cannot fail, or starts its lookup.

Create caches

kind:membertask:create

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:membertask:create

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:membertask:create

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:membertask:create

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

Access values

kind:membertask:access

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:membertask:access

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>

Invalidate values

kind:membertask:invalidate

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:membertask:invalidate

invalidateAll

Cache.invalidateAll cache
Member
Forgets every cached key.

Parameters

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

Returns

Flow<'env, 'none, unit>

Operations

kind:member

getSure

Cache.getSure key cache
Member
Returns the cached value for a key in a cache whose lookup cannot fail, or starts its lookup.

Parameters

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

Returns

Flow<'env, 'error, 'value>

Verification Examples

let render (names: Cache<int, Never, string>) : Flow<unit, PageError, string> =
    names |> Cache.getSure 42