Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (39 sloc) 1.461 kb
d036073 BossDB is now its own project
Evan Miller authored
1 -module(boss_cache_controller).
2
3 -behaviour(gen_server).
4
5 -export([start_link/0, start_link/1]).
6
7 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
8
9 -record(state, {
10 adapter,
11 connection
12 }).
13
14 start_link() ->
15 start_link([]).
16
17 start_link(Args) ->
fd2df1d Manage connections with Poolboy
Evan Miller authored
18 gen_server:start_link(?MODULE, Args, []).
d036073 BossDB is now its own project
Evan Miller authored
19
20 init(Options) ->
21 AdapterName = proplists:get_value(adapter, Options, memcached_bin),
22 Adapter = list_to_atom(lists:concat(["boss_cache_adapter_", AdapterName])),
e0c6e90 start/stop for app, init/terminate for connection
Evan Miller authored
23 {ok, Conn} = Adapter:init(Options),
d036073 BossDB is now its own project
Evan Miller authored
24 {ok, #state{ adapter = Adapter, connection = Conn }}.
25
26 handle_call({get, Prefix, Key}, _From, State) ->
27 Adapter = State#state.adapter,
28 Conn = State#state.connection,
29 {reply, Adapter:get(Conn, Prefix, Key), State};
30 handle_call({set, Prefix, Key, Value, TTL}, _From, State) ->
31 Adapter = State#state.adapter,
32 Conn = State#state.connection,
33 {reply, Adapter:set(Conn, Prefix, Key, Value, TTL), State};
34 handle_call({delete, Prefix, Key}, _From, State) ->
35 Adapter = State#state.adapter,
36 Conn = State#state.connection,
37 {reply, Adapter:delete(Conn, Prefix, Key), State}.
38
39 handle_cast(_Request, State) ->
40 {noreply, State}.
41
42 terminate(_Reason, State) ->
43 Adapter = State#state.adapter,
44 Conn = State#state.connection,
e0c6e90 start/stop for app, init/terminate for connection
Evan Miller authored
45 Adapter:terminate(Conn).
d036073 BossDB is now its own project
Evan Miller authored
46
47 code_change(_OldVsn, State, _Extra) ->
48 {ok, State}.
49
50 handle_info(_Info, State) ->
51 {noreply, State}.
Something went wrong with that request. Please try again.