Simple Memory-based Erlang cache service using ETS.
This is a second fork of library originally written by Andrew Stanton.
This particular version has a few features:
- provides async and sync acesss API (check for
sync_
prefix). - API documentation
- type specs
- unit tests
- ops helpers (check for
ops_
prefix) - conditional sets (credit to Christian Lundgren)
Include it into rebar.config
for rebar3:
{simple_cache, "1.1.3"}
Include it into rebar.config
:
{simple_cache, "",
{git, "git@github.com:tgrk/simple_cache.git", {tag, "1.1.2"}}}
Start OTP application:
_ = application:ensure_all_started(simple_cache).
Insert/update value (optional expiration in ms):
ok = simple_cache:set(<<"foo">>, <<"bar">>),
ok = simple_cache:set(<<"foo">>, <<"bar">>, 5000),
ok = simple_cache:sync_set(<<"foo">>, <<"bar">>),
ok = simple_cache:sync_set(<<"foo">>, <<"bar">>, infinity),
Insert/update value based on predicate result:
PredFun = fun (<<"bar">>) -> false end,
{ok, false} = simple_cache:cond_set<<"foo">>, <<"baz">>, PredFun, infinity).
Get value by key (optional default value):
{ok, <<"bar">>} = simple_cache:lookup(<<"foo">>),
{ok, <<"bar">>} = simple_cache:lookup(<<"foo">>, <<"default">>),
Remove cached values all or by key:
ok = simple_cache:flush().
ok = simple_cache:sync_flush().
ok = simple_cache:flush(<<"foo">>).
Operations helpers:
simple_cache:ops_info().
simple_cache:ops_list().
For more information about usage refer to tests.
- Andrew Stanton - https://github.com/Refefer/simple_cache
- Sergio Veiga - https://github.com/darkua/simle_cache
- Gustav Simonsson - https://github.com/Gustav-Simonsson/simple_cache
- Christian Lundgren - https://github.com/chrisavl/simple_cache