livery_client_cookie_store behaviour (livery v0.4.4)

View Source

Behaviour for the cookie jar's backing store.

livery_client_cookie keeps no cookies of its own; it reads and writes them through this behaviour. The default, livery_client_cookie_store_ets, holds them in a public ETS table created by the jar constructor and shared across the concurrent request processes that run the client. Implement the four callbacks to back a jar with something else (a shared process, an external cache); the jar stays in-memory and per-jar either way.

Cookies and keys are opaque to the store: it persists and returns them without looking inside.

  • init(Opts) -> Store - build the store from the jar/1 opts and return an opaque handle.
  • get(Store) -> [Cookie] - every cookie currently held, in any order.
  • put(Store, Key, Cookie) -> ok - store Cookie under Key, replacing any cookie already there.
  • delete(Store, Key) -> ok - forget the cookie under Key.

Summary

Types

cookie()

-type cookie() :: term().

key()

-type key() :: term().

store()

-type store() :: term().

Callbacks

delete/2

-callback delete(store(), key()) -> ok.

get/1

-callback get(store()) -> [cookie()].

init(Opts)

-callback init(Opts :: map()) -> store().

put/3

-callback put(store(), key(), cookie()) -> ok.