Current section

Files

Jump to
nerves_runtime lib nerves_runtime kv_backend in_memory.ex
Raw

lib/nerves_runtime/kv_backend/in_memory.ex

# SPDX-FileCopyrightText: 2022 Frank Hunleth
#
# SPDX-License-Identifier: Apache-2.0
defmodule Nerves.Runtime.KVBackend.InMemory do
@moduledoc """
In-memory KV store
This KV store keeps everything in memory. Use it by specifying it
as a backend in the application configuration. Specifying an initial
set of contents is optional.
```elixir
config :nerves_runtime, :kv_backend, {Nerves.Runtime.KV.InMemory, contents: %{"key" => "value"}}
```
"""
@behaviour Nerves.Runtime.KVBackend
@impl Nerves.Runtime.KVBackend
def load(options) do
case Keyword.fetch(options, :contents) do
{:ok, contents} when is_map(contents) -> {:ok, contents}
_ -> {:ok, %{}}
end
end
@impl Nerves.Runtime.KVBackend
def save(_new_state, _options), do: :ok
end