Module Storage.Atomic_write

Parameters

module M : Make
module K : Type.S
module V : Type.S

Signature

include Atomic_write_intf.S with type key = K.t and type value = V.t

Atomic write stores

Atomic-write stores are stores where it is possible to read, update and remove elements, with atomically guarantees.

type t

The type for atomic-write backend stores.

Read-only stores

Read-only stores are store where it is only possible to read existing values.

type key = K.t

The type for keys.

type value = V.t

The type for raw values.

val mem : t -> key -> bool

mem t k is true iff k is present in t.

val find : t -> key -> value option

find t k is Some v if k is associated to v in t and None is k is not present in t.

val set : t -> key -> value -> unit

set t k v replaces the contents of k by v in t. If k is not already defined in t, create a fresh binding. Raise Invalid_argument if k is the empty path.

val test_and_set : t -> key -> test:value option -> set:value option -> bool

test_and_set t key ~test ~set sets key to set only if the current value of key is test and in that case returns true. If the current value of key is different, it returns false. None means that the value does not have to exist or is removed.

Note: The operation is guaranteed to be atomic.

val remove : t -> key -> unit

remove t k remove the key k in t.

val list : t -> key list

list t it the list of keys in t.

type watch

The type of watch handlers.

val watch : t -> ?init:(key * value) list -> (key -> value Atomic_write_intf.diff -> unit) -> watch

watch t ?init f adds f to the list of t's watch handlers and returns the watch handler to be used with unwatch. init is the optional initial values. It is more efficient to use watch_key to watch only a single given key.

val watch_key : t -> key -> ?init:value -> (value Atomic_write_intf.diff -> unit) -> watch

watch_key t k ?init f adds f to the list of t's watch handlers for the key k and returns the watch handler to be used with unwatch. init is the optional initial value of the key.

val unwatch : t -> watch -> unit

unwatch t w removes w from t's watch handlers.

val clear : t -> unit

Clear the store. This operation is expected to be slow.

val close : t -> unit

close t frees up all the resources associated with t. Any operations run on a closed handle will raise Closed.

val init : Conf.t -> t

init config is a function returning fresh store handles, with the configuration config, which is provided by the backend.