ExKits.Cache.Storage behaviour (ex_kits v0.2.8)

View Source

A cache storage module that provides a simple interface for storing and retrieving key-value pairs.

Examples

iex> storage = ExKits.Cache.Storage.new([])
iex> ExKits.Cache.Storage.put(storage, :key, "value", [])
:ok
iex> ExKits.Cache.Storage.get(storage, :key)
"value"

Summary

Functions

delete a key-value pair from the cache storage

get the value of a key from the cache storage

put a key-value pair into the cache storage

Types

k()

@type k() :: term()

opts()

@type opts() :: Keyword.t()

put_opts()

@type put_opts() :: [{:ttl, pos_integer() | :infinity}]

t()

@type t() :: struct()

v()

@type v() :: term() | nil

Callbacks

del(t, k)

@callback del(t(), k()) :: any()

get(t, k)

@callback get(t(), k()) :: v()

new(opts)

@callback new(opts()) :: t()

put(t, k, v, put_opts)

@callback put(t(), k(), v(), put_opts()) :: any()

Functions

del(storage, k)

@spec del(t(), k()) :: any()

delete a key-value pair from the cache storage

Examples

iex> storage = ExKits.Storage.ETS.new([])
iex> ExKits.Cache.Storage.del(storage, :key)
:ok

get(storage, k)

@spec get(t(), k()) :: v()

get the value of a key from the cache storage

Examples

iex> storage = ExKits.Storage.ETS.new([])
iex> ExKits.Cache.Storage.get(storage, :key)
nil

put(storage, k, v, opts)

@spec put(t(), k(), v(), put_opts()) :: any()

put a key-value pair into the cache storage

Examples

iex> storage = ExKits.Storage.ETS.new([])
iex> ExKits.Cache.Storage.put(storage, :key, "value", [])
:ok