avrora v0.7.1 Avrora.Storage.Memory View Source
Avora.Storage
behavior implementation which uses memory (ETS).
Schemas can be accessed by integer id or full name.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Delete data from storage by key. Always succeeds, whether or not the key exists.
Tell storage module to delete data after TTL (time to live) expires. Works whether or not the key exists. TTL is in milliseconds.
Get schema by key.
Store schema by key. If value already exists it will be replaced.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Delete data from storage by key. Always succeeds, whether or not the key exists.
Examples
iex> _ = Avrora.Storage.Memory.start_link()
iex> schema = %Avrora.Schema{id: nil, json: "{}"}
iex> Avrora.Storage.Memory.put("my-key", schema)
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
iex> Avrora.Storage.Memory.get("my-key")
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
iex> Avrora.Storage.Memory.delete("my-key")
{:ok, true}
iex> Avrora.Storage.Memory.get("my-key")
{:ok, nil}
Tell storage module to delete data after TTL (time to live) expires. Works whether or not the key exists. TTL is in milliseconds.
Examples
iex> _ = Avrora.Storage.Memory.start_link()
iex> schema = %Avrora.Schema{id: nil, json: "{}"}
iex> Avrora.Storage.Memory.put("my-key", schema)
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
iex> {:ok, _} = Avrora.Storage.Memory.expire("my-key", 100)
iex> Avrora.Storage.Memory.get("my-key")
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
iex> Process.sleep(100)
iex> Avrora.Storage.Memory.get("my-key")
{:ok, nil}
Get schema by key.
Examples
iex> _ = Avrora.Storage.Memory.start_link()
iex> Avrora.Storage.Memory.put("my-key", %{"hello" => "world"})
{:ok, %{"hello" => "world"}}
iex> Avrora.Storage.Memory.get("my-key")
{:ok, %{"hello" => "world"}}
iex> Avrora.Storage.Memory.get("unknown-key")
{:ok, nil}
Store schema by key. If value already exists it will be replaced.
Examples
iex> _ = Avrora.Storage.Memory.start_link()
iex> schema = %Avrora.Schema{id: nil, json: "{}"}
iex> Avrora.Storage.Memory.put("my-key", schema)
{:ok, %Avrora.Schema{id: nil, json: "{}"}}