package janestreet_lru_cache

  1. Overview
  2. Docs

Module Lru_cache.MakeSource

Parameters

module H : H

Signature

Sourcetype key = H.t
Sourcetype 'a t
Sourceval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
Sourceval 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.

Sourceval to_alist : 'a t -> (key * 'a) list

Ordered from least- to most-recently used elements.

Sourceval length : _ t -> int
Sourceval is_empty : _ t -> bool
Sourceval stats : ?sexp_of_key:(key -> Core.Sexp.t) -> _ t -> Core.Sexp.t
Sourceval max_size : _ t -> int
Sourceval 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
Sourceval invariant : ('a -> unit) -> 'a t -> unit
Sourceval 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.

Sourceval find : 'a t -> key -> 'a option
Sourceval 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.

Sourceval set_max_size : _ t -> max_size:int -> [ `Dropped of int ]
Sourceval remove : _ t -> key -> [ `Ok | `No_such_key ]
Sourceval set : 'a t -> key:key -> data:'a -> unit
Sourceval find_or_add : 'a t -> key -> default:(unit -> 'a) -> 'a
Sourceval find_and_remove : 'a t -> key -> 'a option
OCaml

Innovation. Community. Security.