https://github.com/ledest/beamcache
Erlang BEAM cache
https://github.com/ledest/beamcache
cache erlang
Last synced: 4 months ago
JSON representation
Erlang BEAM cache
- Host: GitHub
- URL: https://github.com/ledest/beamcache
- Owner: Ledest
- License: lgpl-2.1
- Created: 2017-07-09T20:05:06.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T21:39:13.000Z (over 1 year ago)
- Last Synced: 2025-10-21T15:38:10.731Z (8 months ago)
- Topics: cache, erlang
- Language: Erlang
- Homepage:
- Size: 45.9 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/Ledest/beamcache/actions/workflows/erlang.yml/badge.svg)
# beamcache: Erlang BEAM Cache
## Usage
```erlang
CacheName = my_cache,
Cache = #{a => 1, b => true, <<"key">> => "TEST"},
{module, CacheName} = beamcache:init(CacheName, Cache),
Cache = CacheName:get(),
true = CacheName:get(b),
false = CacheName:get(c, false).
```
To shut up xref and dialyzer add such module to sources:
```erlang
-module(testbc).
-export([get/0, get/1, get/2]).
get() -> erlang:nif_error(undef).
get(_) -> erlang:nif_error(undef).
get(_, _) -> erlang:nif_error(undef).
erase(_) -> erlang:nif_error(undef).
put(_, _) -> erlang:nif_error(undef).
```
To protect against using uninitialized cache add such module to sources:
```erlang
-module(testbc).
-export(['$handle_undefined_function'/2]).
'$handle_undefined_function'(F, A) ->
{module, ?MODULE} = beamcache:init(?MODULE, #{a => 1, b => true, <<"key">> => "TEST"}),
apply(?MODULE, F, A).
```
Or come up with a combination of the above examples...