forked from darkua/simple_cache
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
simple_cache | ||
============ | ||
[](https://circleci.com/gh/tgrk/simple_cache/tree/master) | ||
[](https://hex.pm/packages/simple_cache) | ||
[](https://codecov.io/github/tgrk/simple_cache?branch=master) | ||
|
||
# simple_cache | ||
|
||
Simple Memory-based Erlang cache service using ETS. | ||
|
||
This is a second fork of library originally written by [Andrew Stanton](https://github.com/Refefer). | ||
|
||
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) | ||
|
||
|
||
Usage | ||
============ | ||
# Usage | ||
|
||
Include it into `rebar.config` for rebar3: | ||
|
||
```erlang | ||
{simple_cache, "1.1.2"} | ||
{simple_cache, "1.1.3"} | ||
``` | ||
|
||
Include it into `rebar.config`: | ||
|
||
```erlang | ||
{simple_cache, "", | ||
{git, "[email protected]:tgrk/simple_cache.git", {tag, "1.1.2"}}} | ||
``` | ||
|
||
Start OTP application: | ||
|
||
```erlang | ||
_ = application:ensure_all_started(simple_cache). | ||
``` | ||
|
||
Insert/update value (optional expiration in ms): | ||
|
||
```erlang | ||
ok = simple_cache:set(<<"foo">>, <<"bar">>), | ||
ok = simple_cache:set(<<"foo">>, <<"bar">>, 5000), | ||
|
@@ -41,35 +48,38 @@ ok = simple_cache:sync_set(<<"foo">>, <<"bar">>, infinity), | |
``` | ||
|
||
Insert/update value based on predicate result: | ||
|
||
```erlang | ||
PredFun = fun (<<"bar">>) -> false end, | ||
{ok, false} = simple_cache:cond_set<<"foo">>, <<"baz">>, PredFun, infinity). | ||
``` | ||
|
||
Get value by key (optional default value): | ||
|
||
```erlang | ||
{ok, <<"bar">>} = simple_cache:lookup(<<"foo">>), | ||
{ok, <<"bar">>} = simple_cache:lookup(<<"foo">>, <<"default">>), | ||
``` | ||
|
||
Remove cached values all or by key: | ||
|
||
```erlang | ||
ok = simple_cache:flush(). | ||
ok = simple_cache:sync_flush(). | ||
ok = simple_cache:flush(<<"foo">>). | ||
``` | ||
|
||
Operations helpers: | ||
|
||
```erlang | ||
simple_cache:ops_info(). | ||
simple_cache:ops_list(). | ||
``` | ||
|
||
|
||
For more information about usage refer to tests. | ||
|
||
Credits | ||
============ | ||
# Credits | ||
|
||
* 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 | ||
|
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