Skip to content

Instantly share code, notes, and snippets.

@hl
Created January 22, 2024 12:27
Show Gist options
  • Save hl/3f5aab4d3625f052d9d746707a082b8f to your computer and use it in GitHub Desktop.
Save hl/3f5aab4d3625f052d9d746707a082b8f to your computer and use it in GitHub Desktop.
simple persistent_term storage
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