Permalink
Browse files

new merge function

  • Loading branch information...
1 parent cc876df commit 0f75eb42ad147b3e75824e23636f419a59012305 @videlalvaro committed May 11, 2010
Showing with 21 additions and 6 deletions.
  1. +21 −6 php_cask.erl
View
@@ -7,13 +7,13 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([get/1, put/2, delete/1, list_keys/0]).
+-export([get/1, put/2, delete/1, list_keys/0, merge/0]).
start() -> gen_server:start({local, ?MODULE}, ?MODULE, [], []).
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
stop() -> gen_server:cast(?MODULE, stop).
--record(state, {ref}).
+-record(state, {ref, dirname, expiry_secs}).
get(Key) -> gen_server:call(?MODULE, {get, Key}).
@@ -25,10 +25,14 @@ delete(Key) ->
list_keys() ->
gen_server:call(?MODULE, {list_keys}).
+
+merge() ->
+ gen_server:call(?MODULE, {merge}).
init([]) ->
- Bitcask = bitcask:open("./data", [read_write]),
- {ok, #state{ref=Bitcask}}.
+ Dirname = get_dirname(),
+ Bitcask = bitcask:open(Dirname, [read_write]),
+ {ok, #state{ref=Bitcask, dirname=Dirname, expiry_secs=get_expiry_secs()}}.
handle_call({get, Key}, _From, #state{ref=Bitcask}=State) ->
Reply =
@@ -48,11 +52,22 @@ handle_call({delete, Key}, _From, #state{ref=Bitcask}=State) ->
handle_call({list_keys}, _From, #state{ref=Bitcask}=State) ->
Reply = bitcask:list_keys(Bitcask),
- {reply, Reply, State}.
+ {reply, Reply, State};
+
+handle_call({merge}, _From, #state{dirname=Dirname, expiry_secs=Expire}=State) ->
+ Options = [{expiry_secs, Expire}],
+ bitcask:merge(Dirname, Options),
+ {reply, ok, State}.
handle_cast(stop, State) -> {stop, normal, State}.
handle_info(_Info, State) ->
error_logger:info_msg("handle_info ~p ~p.~n", [_Info, State]),
{noreply, State}.
terminate(_Reason, _State) -> ok.
-code_change(_OldVsn, State, _Extra) -> {ok, State}.
+code_change(_OldVsn, State, _Extra) -> {ok, State}.
+
+get_dirname() ->
+ "./data".
+
+get_expiry_secs() ->
+ 900.

0 comments on commit 0f75eb4

Please sign in to comment.