Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major updates for 23.3 #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ doc/edoc-info
doc/doc
tests/
/erl_cache
/_build
/.erl_cache.plt
/TEST*
/rebar.lock
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@ before_install:
script: "make get-deps compile test docs"

otp_release:
- 17.0
- R16B03-1
- R16B02
- R16B01
- R15B03
- R15B02
- R15B01
- 23.3.1
34 changes: 12 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
REBAR ?= rebar
REBAR ?= rebar3
ifneq ($(wildcard rebar),)
REBAR := ./rebar
REBAR := ./rebar3
endif

.PHONY: clean test docs benchmark docsclean go quick dialyzer
.PHONY: clean test docs docsclean go compile get-deps dialyzer

all: get-deps compile

get-deps:
$(REBAR) get-deps

compile:
$(REBAR) compile
$(REBAR) skip_deps=true xref

quick:
$(REBAR) skip_deps=true compile
$(REBAR) skip_deps=true xref
$(REBAR) compile xref

clean:
$(REBAR) clean
rm -f erl_cache
rm -fr _build

test: compile
$(REBAR) skip_deps=true eunit
$(REBAR) eunit --cover

docs: docsclean
ln -s . doc/doc
$(REBAR) skip_deps=true doc
$(REBAR) edoc

docsclean:
rm -f doc/*.html doc/*.css doc/erlang.png doc/edoc-info doc/doc

go:
erl -name erl_cache -pa deps/*/ebin -pa ebin/ -s erl_cache start ${EXTRA_ARGS}

dialyzer:
dialyzer -c ebin/ -Wunmatched_returns -Werror_handling -Wrace_conditions
$(REBAR) shell

erl_cache:
REBAR_BENCH=1 $(REBAR) get-deps compile
REBAR_BENCH=1 $(REBAR) escriptize skip_deps=true
.erl_cache.plt:
dialyzer --output_plt $@ --build_plt --apps erts kernel stdlib

benchmark: erl_cache quick
./erl_cache priv/bench.conf
dialyzer: .erl_cache.plt compile
dialyzer --plt $< -c _build/default/deps/erl_cache/ebin/ -Wunknown -Wunmatched_returns
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,3 @@ running out of the configured memory for the cache ets.
The memory control mechanism is not accurate and doesn't deal properly with cached large binaries,
since the cache ets will only store references to them and it's not possible to figure the exact
size of the referenced binaries.

<h3>Benchmarking</h3>
This application has a ready benchmarking suite. It is based on basho bench. To
run the benchmark:

<pre>
$ make benchmark<br/>
</pre>

In order to render the results (gnuplot is needed):
<pre>
$ ./deps/basho_bench/priv/gp_throughput.sh
</pre>

For full usage guide please consult <a
href="http://docs.basho.com/riak/latest/ops/building/benchmarking/">basho bench
documentation</a>.
11 changes: 0 additions & 11 deletions include/logging.hrl

This file was deleted.

10 changes: 0 additions & 10 deletions priv/bench.conf

This file was deleted.

16 changes: 1 addition & 15 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{cover_print_enabled,true}.

{deps,[
{lager,[],{git,"git://github.com/spilgames/lager.git",{tag,"2.0.3"}}},
{decorator_pt,[],{git,"git://github.com/spilgames/erl-decorator-pt.git",{tag,"1.0.2"}}}
]}.

Expand All @@ -15,17 +14,4 @@

{eunit_opts,[verbose,{report,{eunit_surefire,[{dir,"."}]}}]}.

{xref_checks,[undefined_function_calls]}.

{escript_incl_apps, [
basho_bench,

% Copied from basho_bench/rebar.config
lager, getopt, bear, folsom, ibrowse, riakc, riak_pb, mochiweb,
protobuffs, velvet, goldrush
]}.

{erl_opts, [{platform_define, "17|18", 'namespace_types'},
debug_info,
{src_dirs, [src]},
{parse_transform, lager_transform}]}.
{erl_opts, [debug_info, {i, "include"}, {src_dirs, [src]}]}.
16 changes: 0 additions & 16 deletions rebar.config.script

This file was deleted.

3 changes: 1 addition & 2 deletions src/erl_cache.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
{registered, []},
{applications, [
kernel,
stdlib,
lager
stdlib
]},
{mod, { erl_cache_app, []}},
{env, []}
Expand Down
43 changes: 13 additions & 30 deletions src/erl_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
-behaviour(gen_server).

-include("erl_cache.hrl").
-include("logging.hrl").

%% ==================================================================
%% Escript API
%% ==================================================================
-export([main/1]).
-include_lib("kernel/include/logger.hrl").

%% ==================================================================
%% API Function Exports
Expand All @@ -26,11 +21,6 @@
evict/2, evict/3
]).

-ignore_xref([
{basho_bench, main, 1}
]).


-type name() :: atom(). %% The identifeir for a cache server
-type key() :: term(). %% The identifier for a cache entry
-type value() :: term().%% The value associated with a cache key
Expand Down Expand Up @@ -59,14 +49,14 @@

-type key_generation_module()::atom(). %% A module implementing the erl_cache_key_generator behaviour.

-type cache_get_opt()::{wait_for_refresh, wait_for_refresh()}.

-type cache_size()::non_neg_integer(). %% Soft limit to the cache size in MB
-type cache_server_opt()::
{max_cache_size, cache_size() | undefined} %% NOTE: this limit is soft and particularly
%% innaccurate when working with large binaries!
| {mem_check_interval, pos_integer()}.

-type cache_get_opt()::{wait_for_refresh, wait_for_refresh()}.
-type cache_set_opt() ::
{validity, validity()} |
{evict, evict()} |
Expand All @@ -76,6 +66,7 @@
{is_error_callback, is_error_callback()} |
{refresh_callback, refresh_callback()}.
-type cache_evict_opt() :: {wait_until_done, wait_until_done()}.
-type decorator_opts()::[cache_get_opt() | cache_set_opt()].
-type cache_opts()::[cache_get_opt() | cache_set_opt() | cache_evict_opt()
| {evict_interval, evict_interval()} | cache_server_opt()].

Expand All @@ -84,15 +75,16 @@
{miss, non_neg_integer()}.
-type cache_stats()::[cache_stat()].

-type config_key()::validity | evict | refresh_callback | wait_for_refresh
| wait_until_done | evict_interval | is_error_callback | error_validity.
-type config_key()::validity | evict | refresh_callback | wait_for_refresh | max_cache_size
| wait_until_done | evict_interval | is_error_callback | error_validity
| mem_check_interval | key_generation.

-type callback() :: function() | mfa().
-type callback() :: function() | {atom(), atom(), [term()]}.

-export_type([
name/0, key/0, value/0, validity/0, evict/0, evict_interval/0, refresh_callback/0,
cache_stats/0, wait_for_refresh/0, wait_until_done/0, error_validity/0, is_error_callback/0,
cache_size/0, cache_opts/0
cache_size/0, cache_opts/0, decorator_opts/0
]).

%% ==================================================================
Expand All @@ -109,13 +101,6 @@
-define(CACHE_MAP, cache_map).
-define(SERVER, ?MODULE).


%% ====================================================================
%% Escript
%% ====================================================================
main(Args) ->
basho_bench:main(Args).

%% ====================================================================
%% API
%% ====================================================================
Expand All @@ -124,7 +109,6 @@ main(Args) ->
-spec start() -> ok.
%% @end
start() ->
ok = lager:start(),
ok = application:start(erl_cache).

%% @private
Expand Down Expand Up @@ -162,7 +146,7 @@ set_cache_defaults(Name, CacheOpts) ->
end.

%% @doc Gets the default value of a cache server option.
-spec get_cache_option(name(), cache_opts()) -> term().
-spec get_cache_option(name(), config_key()) -> term().
%% @end
get_cache_option(Name, Opt) ->
case ets:lookup(?CACHE_MAP, Name) of
Expand Down Expand Up @@ -192,7 +176,7 @@ list_cache_servers() ->
ets:select(?CACHE_MAP, [{{'$1', '_'}, [], ['$1']}]).

%% @doc Gets the value associated with a given key in the cache signaled by the given name.
-spec get(name(), key(), [cache_get_opt()]) ->
-spec get(name(), key(), cache_opts()) ->
{error, not_found} |
{error, invalid_opt_error()} |
{ok, value()}.
Expand Down Expand Up @@ -222,7 +206,7 @@ set(Name, Key, Value) ->
%% @doc Sets a cache entry in a cache instance.
%% The options passed in this function call will overwrite the default ones for the cache instance
%% for any operation related to this specific key.
-spec set(name(), key(), value(), [cache_set_opt()]) -> ok | {error, invalid_opt_error()}.
-spec set(name(), key(), value(), cache_opts()) -> ok | {error, invalid_opt_error()}.
%% @end
set(Name, Key, Value, Opts) ->
case validate_opts(Opts, get_name_defaults(Name)) of
Expand Down Expand Up @@ -281,7 +265,7 @@ handle_call({stop_cache, Name}, _From, #state{}=State) ->
Res = case is_cache_server(Name) of
true ->
ok = erl_cache_server_sup:remove_cache(Name),
?INFO("Stopping cache server '~p'", [Name]),
?LOG_INFO("Stopping cache server '~p'", [Name]),
true = ets:delete(?CACHE_MAP, Name),
ok;
false ->
Expand All @@ -300,7 +284,7 @@ do_start_cache(Name, Opts) ->
case validate_opts(Opts, []) of
{ok, ValidatedOpts} ->
true = ets:insert(?CACHE_MAP, {Name, ValidatedOpts}),
?INFO("Starting cache server '~p'", [Name]),
?LOG_INFO("Starting cache server '~p'", [Name]),
{ok, _} = erl_cache_server_sup:add_cache(Name),
ok;
{error, _}=E -> E
Expand Down Expand Up @@ -449,4 +433,3 @@ get_name_defaults(Name) ->
[{Name, Opts}] -> Opts;
[] -> undefined
end.

6 changes: 3 additions & 3 deletions src/erl_cache_decorator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
%% API
%% ====================================================================

-spec cache_pt(function(), [term()], {atom(), atom(), erl_cache:name(), erl_cache:cache_opts()}) ->
(fun(() -> term())).
-spec cache_pt(function(), [term()], {atom(), atom(), erl_cache:name(),
[erl_cache:cache_opts()]}) ->
(fun(() -> term())) | no_return().
cache_pt(Fun, Args, {Module, FunctionAtom, Name, Opts}) ->
FinalOpts = [{refresh_callback, fun () -> Fun(Args) end} | Opts],
Key = case proplists:get_value(key_generation, Opts) of
Expand All @@ -28,4 +29,3 @@ cache_pt(Fun, Args, {Module, FunctionAtom, Name, Opts}) ->
{error, Err} ->
throw({error, {cache_pt, Err}})
end.

24 changes: 0 additions & 24 deletions src/erl_cache_driver.erl

This file was deleted.

Loading