xturn_cache v0.1.1 Xirsys.XTurn.Cache.Store View Source

Simple caching module with TTL, used by the XTurn TURN server project.

Link to this section Summary

Functions

Add a value by key.

Add multiple key / value's.

Returns a specification to start this module under a supervisor.

Returns the value of a key in an erlang success tuple.

Returns the value of a key or nil if not exists.

Returns the agent state as a raw map.

Returns true if a key exists; otherwise false.

Create a cache context.

Create a cache context with specified TTL.

Create a cache context with specified TTL and onTTL callback.

Returns the number of keys in the cache.

Returns all the keys in the cache.

Removes a key and its value.

Destroys the cache (cleanup).

Not to be called directly. Used by the cache to timeout keys.

Link to this section Functions

Link to this function

append(agent, arg)

View Source
append(pid(), {term(), term()}) :: :ok | no_return()

Add a value by key.

Returns :ok

Examples

iex> ctx = Xirsys.XTurn.Cache.Store.init()
{:ok, pid()}
iex> Xirsys.XTurn.Cache.Store.append(ctx, {"key", "value"})
:ok
Link to this function

append_many(agent, elems)

View Source
append_many(pid(), [{term(), term()}]) :: :ok | no_return()

Add multiple key / value's.

Returns :ok

Examples

iex> ctx = Xirsys.XTurn.Cache.Store.init()
{:ok, pid()}
iex> Xirsys.XTurn.Cache.Store.append_items_to_store(ctx, [{"key", "value"}, {"key2", "value2"}])
:ok

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

fetch(agent, id)

View Source
fetch(pid(), term()) :: {:ok, term()} | :error

Returns the value of a key in an erlang success tuple.

Link to this function

fetch!(agent, id)

View Source
fetch!(pid(), term()) :: term() | nil

Returns the value of a key or nil if not exists.

Link to this function

get_state(agent)

View Source
get_state(pid()) :: map()

Returns the agent state as a raw map.

Link to this function

has_key?(agent, id)

View Source
has_key?(pid(), term()) :: boolean()

Returns true if a key exists; otherwise false.

Create a cache context.

Link to this function

init(lifetime)

View Source
init(integer()) :: {:ok, pid()}

Create a cache context with specified TTL.

Link to this function

init(lifetime, callback)

View Source

Create a cache context with specified TTL and onTTL callback.

Link to this function

item_count(agent)

View Source
item_count(pid()) :: integer()

Returns the number of keys in the cache.

Returns all the keys in the cache.

Link to this function

remove(agent, id)

View Source
remove(pid(), term()) :: :ok | no_return()

Removes a key and its value.

Returns :ok

Examples

iex> ctx = Xirsys.XTurn.Cache.Store.init()
{:ok, pid()}
iex> Xirsys.XTurn.Cache.Store.append_item_to_store(ctx, {"key", "value"})
:ok
iex> Xirsys.XTurn.Cache.Store.remove_item_from_store(ctx, "key")
:ok
Link to this function

terminate(agent)

View Source
terminate(pid()) :: :ok

Destroys the cache (cleanup).

Link to this function

timer_callback(agent, id)

View Source

Not to be called directly. Used by the cache to timeout keys.