Logo Orsak

MemoryCache Module

Effects for caching values in the environment's IMemoryCache.

Functions and values

Function or value Description

getOrCreate key f

Full Usage: getOrCreate key f

Parameters:
    key : 'a - The key of the cached value.
    f : ICacheEntry -> Effect<'a0, 'entry, 'Err> - Creates the effect that produces the value, when it is not cached.

Returns: Effect<'a0, 'entry, 'Err>
Type parameters: 'a, 'a, 'entry, 'Err (requires :> Orsak.ICacheProvider)

Gets the value cached under key, or runs the effect created by f to create and cache it. f is given the new cache entry, to set e.g. its expiration.

key : 'a

The key of the cached value.

f : ICacheEntry -> Effect<'a0, 'entry, 'Err>

Creates the effect that produces the value, when it is not cached.

Returns: Effect<'a0, 'entry, 'Err>
Example

 let getCustomer (id: int) =
     MemoryCache.getOrCreate id (fun entry -> eff {
         entry.SetAbsoluteExpiration(TimeSpan.FromMinutes 5.0) |> ignore
         return! Customers.load id
     })
val getCustomer: id: int -> 'a
val id: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val ignore: value: 'T -> unit

updateOrDefault key defaultValue f

Full Usage: updateOrDefault key defaultValue f

Parameters:
    key : string - The key of the cached value.
    defaultValue : 'entry - The value to cache, and return, when nothing is cached under the key.
    f : 'entry -> Effect<'a, 'entry, 'Err> - Creates the effect that produces the updated value from the cached one.

Returns: Effect<'a, 'entry, 'Err> The updated value, or defaultValue.
Type parameters: 'entry, 'a, 'Err (requires :> Orsak.ICacheProvider)

Updates the value cached under key with the effect created by f, or caches defaultValue if there is none.

key : string

The key of the cached value.

defaultValue : 'entry

The value to cache, and return, when nothing is cached under the key.

f : 'entry -> Effect<'a, 'entry, 'Err>

Creates the effect that produces the updated value from the cached one.

Returns: Effect<'a, 'entry, 'Err>

The updated value, or defaultValue.

Type something to start searching.