A very small wrapper around ETS, providing a more user-friendly key/value interface for new users.
Stash automatically creates a single ETS table with a set of defaults options to get running quickly. This library is meant as a fast way to use ETS without needing anything flashy. If you need a more fully featured caching solutions, please check out cachex instead.
This package can be installed via Hex, just add stash to your list of dependencies in mix.exs:
def deps do
[{:stash, "~> 2.0"}]
endIt's straightforward to get up and running quickly, just populate a namespace:
iex(1)> Stash.put(:namespace, "my_key", "my_value")
true
iex(2)> Stash.get(:namespace, "my_key")
"my_value"
iex(3)> Stash.delete(:namespace, "my_key")
true
iex(4)> Stash.get(:namespace, "my_key")
nilStash uses a single table to store all namespaces, and is automatically bootstrapped during
application startup. Tables are created with currency enabled, and act as :set. In older
versions of Stash it was possible to bring your own table, but this has been removed in 2.x.
For further examples, as well as the rest of the API, please see the documentation.
Useful for scripting and/or local tools, Stash includes (de)serialization to/from disk via :dets.
This is accessible via Stash.persist/1 which will move your ETS tables into DTs, allowing you to
reload after your process has died. This is not synced in any way; call Stash.persist/1 repeatedly
if this is required.
iex(1)> Stash.put(:my_table, "key", "value")
true
iex(2)> Stash.size(:my_table)
1
iex(3)> Stash.persist("/tmp/my_persistence_file")Reloading this data can be done via Stash.load/1, which accepts the same arguments:
iex(6)> Stash.load("/tmp/my_persistence_file")
:ok
iex(7)> Stash.size(:my_table)
1
iex(1)> Stash.get(:my_table, "key")
"value"Again, very simple but it does the job :).
I expect the shape of this library will not change much due to the intended use case, but feel free to suggest any improvements! You can test any changes as you'd expect:
$ mix test --traceIf you have any issues or feedback, please file an issue!