ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - whitfin/stash: A small and user-friendly ETS wrapper for caching in Elixir
A small and user-friendly ETS wrapper for caching in Elixir - whitfin/stash
Visit Site

GitHub - whitfin/stash: A small and user-friendly ETS wrapper for caching in Elixir

GitHub - whitfin/stash: A small and user-friendly ETS wrapper for caching in Elixir

Stash

Build Status

A very small wrapping implementation around ETS, providing a more user-friendly key/value interface for new users. Takes care of setting up a new ETS table as needed with a default set of options to avoid having to deal with configurations. This library is meant as a fast way to use ETS without anything flashy, so don't expect many features over what's already here (which isn't much, intentionally).

Installation

This package can be installed via Hex, just add stash to your list of dependencies in mix.exs:

def deps do
  [{:stash, "~> 1.0.0"}]
end

Quick Usage

It's straightforward to get going:

iex(1)> Stash.set(:my_cache, "my_key", "my_value")
true
iex(2)> Stash.get(:my_cache, "my_key")
"my_value"
iex(3)> Stash.delete(:my_cache, "my_key")
true
iex(4)> Stash.get(:my_cache, "my_key")
nil

For further examples, as well as the rest of the API, please see the documentation.

A Note On Table Configuration

By default, Stash will create a table with the following configuration:

[
  { :read_concurrency, true },
  { :write_concurrency, true },
  :public,
  :set,
  :named_table
]

If you don't wish to have this configuration, please create your ETS table in advance of using Stash to access it. However keep in mind that Stash is written with the assumption that you're using either a set or ordered_set, so it's best to stick to those. The defaults should be ok in most cases, so unless you're already thinking that you want a setting changed above, you're probably fine.

Persistence

A neat little feature is the ability to persist a cache to disk, by calling Stash.persist/2. This will move your ETS tables into DTS, allowing you to reload after your process has died. This is not kept in sync due to the overhead involved, so it might be an idea to schedule persistance if you rely on it. To reload, call Stash.load/2.

iex(1)> Stash.set(:my_cache, "key", "value")
true
iex(2)> Stash.size(:my_cache)
1
iex(3)> Stash.persist(:my_cache, "/tmp/my_persistence_file")
:ok
iex(4)> Stash.delete(:my_cache, "key")
true
iex(5)> Stash.size(:my_cache)
0
iex(6)> Stash.load(:my_cache, "/tmp/my_persistence_file")
:ok
iex(7)> Stash.size(:my_cache)
1
iex(1)> Stash.get(:my_cache, "key")
"value"

Issues/Contributions

If you spot any issues with the implementation, please file an issue or even a PR. Like I mentioned above, not too many features will make it into this lib as it's a small wrapping library, nothing special.

Make sure to test your changes though!

$ mix test --trace

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory