Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds expire time as parameter to merge

  • Loading branch information...
commit b15fd58413f4f3a9aafb3b6dec7e07c2bbc9e7d5 1 parent ad14922
@videlalvaro authored
Showing with 7 additions and 14 deletions.
  1. +1 −5 ebin/phpcask.app
  2. +6 −9 src/phpcask.erl
View
6 ebin/phpcask.app
@@ -17,10 +17,6 @@
{env, [
%% Default folder to store bitcask files.
- {dirname, "./priv/data"},
-
- %% Expiration time in seconds for the session data.
- {expiry_secs, 900}
-
+ {dirname, "./priv/data"}
]}
]}.
View
15 src/phpcask.erl
@@ -7,7 +7,7 @@
-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, merge/0]).
+-export([get/1, put/2, delete/1, list_keys/0, merge/1]).
-define(DEFAULT_DIR, "./priv/data").
-define(EXPIRY_SECS, 900).
@@ -17,7 +17,7 @@ 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, dirname, expiry_secs}).
+-record(state, {ref, dirname}).
get(Key) -> gen_server:call(?MODULE, {get, Key}).
@@ -30,13 +30,13 @@ delete(Key) ->
list_keys() ->
gen_server:call(?MODULE, {list_keys}).
-merge() ->
- gen_server:call(?MODULE, {merge}).
+merge(Expire) when is_integer(Expire) ->
+ gen_server:call(?MODULE, {merge, Expire}).
init([]) ->
Dirname = get_dirname(),
Bitcask = bitcask:open(Dirname, [read_write]),
- {ok, #state{ref=Bitcask, dirname=Dirname, expiry_secs=get_expiry_secs()}}.
+ {ok, #state{ref=Bitcask, dirname=Dirname}}.
handle_call({get, Key}, _From, #state{ref=Bitcask}=State) ->
Reply =
@@ -58,7 +58,7 @@ handle_call({list_keys}, _From, #state{ref=Bitcask}=State) ->
Reply = bitcask:list_keys(Bitcask),
{reply, Reply, State};
-handle_call({merge}, _From, #state{dirname=Dirname, expiry_secs=Expire}=State) ->
+handle_call({merge, Expire}, _From, #state{dirname=Dirname}=State) ->
Options = [{expiry_secs, Expire}],
bitcask:merge(Dirname, Options),
{reply, ok, State}.
@@ -72,9 +72,6 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
get_dirname() ->
get_opt(dirname, ?DEFAULT_DIR).
-
-get_expiry_secs() ->
- get_opt(expiry_secs, ?EXPIRY_SECS).
get_opt(Key, Default) ->
case application:get_env(bitcask, Key) of
Please sign in to comment.
Something went wrong with that request. Please try again.