View Source Avrora.Storage.Memory (avrora v0.28.0)
Avora.Storage
behavior implementation which uses memory (ETS).
Schemas can be accessed by integer id or full name.
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.
Complete clean up of the storage. Useful for testing.
Get schema by key.
Store schema by key. If value already exists it will be replaced.
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
...> _ = Avrora.Storage.Memory.start_link()
...> schema = %Avrora.Schema{id: nil, json: "{}"}
...> Avrora.Storage.Memory.put("my-key", schema)
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
...> {:ok, _} = Avrora.Storage.Memory.expire("my-key", 100)
...> Avrora.Storage.Memory.get("my-key")
{:ok, %Avrora.Schema{id: nil, json: "{}"}}
...> Process.sleep(200)
...> Avrora.Storage.Memory.get("my-key")
{:ok, nil}
Complete clean up of the storage. Useful for testing.
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.flush()
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: "{}"}}