package aches-lwt

  1. Overview
  2. Docs

Module Aches_lwtSource

Aches-lwt: a variety of caches for promises

Aches_lwt is a library that provides caches (limited-size collections with automatic discarding of supernumerary elements) for a variety of uses around Lwt promises.

Lwt promises are I/O-dependent values which can take time to resolve. As such, using them in a more standard value cache (e.g., as provided by Aches) can lead to race conditions. The most common scenario leading to a race condition is because of the possible delay between testing whether a value is held in a cache and resolving a fresh value:

  (* with a normal cache holding non-promise values *)
  match find_opt c k with
  | None ->
      (* value is not there *)
      let* v = … in (* make missing values *)
      (* oops the Lwt scheduler has kicked in and there is delay here *)
      replace c k v; (* insert *)
      … (* use [v] *)
  | Some v ->
      … (* use [v] *)

Aches-lwt avoids these race conditions by working directly with promises in the backend, providing a carefully selected API and maintaining a strict cancelling discipline.

Sourcemodule Lache = Lache

Lwt-promise caches