Created
January 22, 2024 12:27
-
-
Save hl/3f5aab4d3625f052d9d746707a082b8f to your computer and use it in GitHub Desktop.
simple persistent_term storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Storage do | |
@moduledoc """ | |
This module provides a wrapper around the :persistent_term module | |
https://www.erlang.org/doc/man/persistent_term | |
""" | |
@type storage :: atom() | |
@type key :: atom() | |
@type value :: any() | |
@spec get(storage(), key()) :: value() | |
def get(storage \\ __MODULE__, key) when is_atom(key) do | |
:persistent_term.get({storage, key}, nil) | |
end | |
@spec put(storage(), key(), value()) :: :ok | |
def put(storage \\ __MODULE__, key, value) when is_atom(key) do | |
:persistent_term.put({storage, key}, value) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment