Ussd.Cache behaviour (Ussd v0.2.0)

Copy Markdown View Source

The storage contract Ussd.Record (and therefore session state) is built on.

Ship your own implementation (backed by Redis, :cachex, Mnesia, ...) and point Ussd.Record at it via config :ussd, :cache, MyApp.UssdCache, or via Ussd.use_store/2 per-request. The default, Ussd.Cache.ETS, is process-local and fine for a single node; anything multi-node needs a shared backend.

Summary

Callbacks

Subtracts amount from key, treating an unset key as starting from 0, and returns the new value.

Deletes key.

Reads key, or default if it's unset or has expired.

Whether key is currently set (and not expired).

Adds amount to key, treating an unset key as starting from 0, and returns the new value.

Stores value under key. ttl, in seconds, is nil when the value should never expire on its own.

Types

key()

@type key() :: String.t()

ttl()

@type ttl() :: pos_integer() | nil

Callbacks

decrement(key, amount)

@callback decrement(key(), amount :: integer()) :: integer()

Subtracts amount from key, treating an unset key as starting from 0, and returns the new value.

forget(key)

@callback forget(key()) :: :ok

Deletes key.

get(key, default)

@callback get(key(), default :: term()) :: term()

Reads key, or default if it's unset or has expired.

has?(key)

@callback has?(key()) :: boolean()

Whether key is currently set (and not expired).

increment(key, amount)

@callback increment(key(), amount :: integer()) :: integer()

Adds amount to key, treating an unset key as starting from 0, and returns the new value.

set(key, value, ttl)

@callback set(key(), value :: term(), ttl()) :: :ok

Stores value under key. ttl, in seconds, is nil when the value should never expire on its own.