package lru_cache

  1. Overview
  2. Docs

Parameters

module M : Monad
module K : Key

Signature

type key = K.t
type 'a monad = 'a M.t
type 'a t

The type of cache from keys of type key to values of type 'a. Cache access must be protected by mutex in a multithread environment. This is not needed when using Async or Lwt. In these cases, the computation function passed to get should return a Deferred.t of Lwt.t.

val init : ?validate:('a monad -> bool monad) -> int -> 'a t

init size creates a new cache, size being the maximum number of entries in the cache.

  • parameter validate

    an optional function which returns whether a computed value must be kept in cache. Default function always returns true.

val in_cache : 'a t -> key -> bool

Whether the value associate to the given key is in the cache.

val get : 'a t -> ?validate:('a monad -> bool monad) -> key -> (key -> 'a monad) -> 'a monad

get cache key compute returns the value associated to key in the cache and set this key as the most recently used. If no value is associated to this key, remove the least recently used (key,value) pair from the cache (if the cache is full) and add (key, compute key), setting this pair as the most recently used.

  • parameter validate

    an optional function which returns whether a computed value must be kept in cache. Default function is the validate function given to init.

val remove : 'a t -> key -> bool
OCaml

Innovation. Community. Security.