package session

  1. Overview
  2. Docs

In-memory backend using the S.Now signature.

The default expiry period is one week.

include S.Now with type key = string and type value = string and type period = int64
type t

The type of a handle on the backend.

type key = string

The type of a session key.

type value = string

The type of a session value.

type period = int64

The type of a session expiry period.

val default_period : t -> period

default_period t returns default period after which session keys will expire. Depending on the backend, this value may vary over time.

val generate : ?expiry:period -> ?value:value -> t -> key

generate ?expiry ?value t will allocate a new session in the backend t and return its associated key. The session will expire expiry seconds from now, defaulting to default_period t if one is not explicitly specified.

The key should be unique, though it may not be in order to allow implementations that use randomness or hashing to conform to this interface.

val clear : t -> key -> unit

clear t key removes key from the backend t. The backend may choose to persist the session value beyond this call, but any subsequent calls operations involving key should behave as if key is not present in the backend.

val get : t -> key -> (value * period, S.error) Result.result

get t key returns the session value, if present and unexpired, together with its expiry period as of now.

val set : ?expiry:period -> t -> key -> value -> unit

set ?expiry t key value sets the value for the session associated key in backend t and sets the session to expire expiry seconds from now. If expiry is not provided, the expiry period reported by default_period t will be used instead.

val create : unit -> t

create () returns the handle on a new in-memory store.

val set_default_period : t -> period -> unit

set_default_period t period sets the default expiry period of t. This will only affect future operations.

OCaml

Innovation. Community. Security.