Library
Module
Module type
Parameter
Class
Class type
type key = H.t
val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val create :
?destruct:((key * 'a) Core.Queue.t -> unit) ->
max_size:int ->
unit ->
'a t
Creates an LRU cache.
destruct
is called on all elements removed from the cache, both implicilty (e.g. set
) or explicitly (e.g. remove
, clear
). destruct
may raise; the exceptions pass through to the caller of the operation that triggered the removal.
val length : _ t -> int
val is_empty : _ t -> bool
val stats : ?sexp_of_key:(key -> Core.Sexp.t) -> _ t -> Core.Sexp.t
val max_size : _ t -> int
val hit_rate : _ t -> float
hit_rate
is the ratio of calls to mem
, find
, and similar functions that queried for a key that was in the cache.
include Core.Invariant.S1 with type 'a t := 'a t
val invariant : ('a -> unit) -> 'a t -> unit
mem
and find
are considered as uses of the key, thus these operation refresh the priority of the key for the computation of the lru heuristic.
val clear : _ t -> [ `Dropped of int ]
Write operations on the t
may drop some of the least recently used elements if the size exceeds the maximum size authorized.
val set_max_size : _ t -> max_size:int -> [ `Dropped of int ]