package janestreet_lru_cache

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Parameters

module H : H

Signature

type key = H.t
type 'a 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 to_alist : 'a t -> (key * 'a) list

Ordered from least- to most-recently used elements.

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 Base__Invariant_intf.inv -> 'a t Base__Invariant_intf.inv
val mem : _ t -> key -> bool

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 find : 'a t -> key -> 'a option
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 ]
val remove : _ t -> key -> [ `Ok | `No_such_key ]
val set : 'a t -> key:key -> data:'a -> unit
val find_or_add : 'a t -> key -> default:(unit -> 'a) -> 'a
val find_and_remove : 'a t -> key -> 'a option
OCaml

Innovation. Community. Security.