Module Data.Cache

Generic caching.

Use T.Cache module if you want to cache values of type T.t.

Use Data.Cache.digest to build digests of the data for caching.

type 'a t

cacher type class

val create : load:(digest -> 'a option) -> save:(digest -> 'a -> unit) -> 'a t

create ~load ~save creates a cache provider.

val digest : namespace:string -> ('a, Stdlib.Format.formatter, unit, digest) Core_kernel.format4 -> 'a

digest ~namespace fmt x y z ... a variadic function to create data digests. Use it like a printf, e.g.,

type t = {name : string; parent : string; lang : string}

let digest t = Data.Cache.digest ~namespace:"student" "%s%s"
    t.name t.parent

In the example, we created a digest that will ignore lang field of the data type (that is assumed to be transparent to the cached computation).

Note: digest function will first eagerly build the whole string and then convert it to the digest. So it has O(N) complexity in space and time, where N is the total size of all constituting elements. If N is too big (hundreds of megabytes) then use Digest module for building digests incrementally.

module Digest : sig ... end

Data digesting for caching.

val load : 'a t -> digest -> 'a option

load cls digest loads entry with a given digest from the cache. Note, this is a generic function, if you want to load a value of type T.t use T.Cache.load function.

val save : 'a t -> digest -> 'a -> unit

save cls digest x stores entry x with a given digest to the cache. Note, this is a generic function, if you want to store a value of type T.t use T.Cache.save function.

type service = {
  1. create : 'a. 'a reader -> 'a writer -> 'a t;
}

service signature

module Service : sig ... end

Service injection point.