View Source ExKits.Cache.Storage behaviour (ex_kits v0.2.7)

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

@type k() :: term()
@type opts() :: Keyword.t()
@type put_opts() :: [{:ttl, pos_integer() | :infinity}]
@type t() :: struct()
@type v() :: term() | nil

Callbacks

@callback del(t(), k()) :: any()
@callback get(t(), k()) :: v()
@callback new(opts()) :: t()
@callback put(t(), k(), v(), put_opts()) :: any()

Functions

@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
@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
Link to this function

put(storage, k, v, opts)

View Source
@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