<commit_before>-module(boss_cache_controller).

-behaviour(gen_server).

-export([start_link/0, start_link/1]).

-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

-record(state, {
        adapter,
        connection
    }).

start_link() ->
    start_link([]).

start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

init(Options) ->
    AdapterName = proplists:get_value(adapter, Options, memcached_bin),
    Adapter	= list_to_atom(lists:concat(["boss_cache_adapter_", AdapterName])),
    {ok, Conn}	= Adapter:init(Options),
    {ok, #state{ adapter = Adapter, connection = Conn }}.

handle_call({get, Prefix, Key}, 
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:get(Conn, Prefix, Key), State};
handle_call({set, Prefix, Key, Value, TTL},
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:set(Conn, Prefix, Key, Value, TTL), State};
handle_call({delete, Prefix, Key}, 
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:delete(Conn, Prefix, Key), State}.
<commit_msg>Check if cache adapter is already started<commit_after>-module(boss_cache_controller).

-behaviour(gen_server).

-export([start_link/0, start_link/1]).

-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).

-record(state, {
        adapter,
        connection
    }).

start_link() ->
    start_link([]).

start_link(Args) ->
    gen_server:start_link(?MODULE, Args, []).

init(Options) ->
    AdapterName = proplists:get_value(adapter, Options, memcached_bin),
    Adapter	= list_to_atom(lists:concat(["boss_cache_adapter_", AdapterName])),
    Conn= case Adapter:init(Options) of
              {ok, _C} ->
                  _C;
              {error,{already_started,_C}}->
                  _C
          end,
    {ok, #state{ adapter = Adapter, connection = Conn }}.

handle_call({get, Prefix, Key}, 
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:get(Conn, Prefix, Key), State};
handle_call({set, Prefix, Key, Value, TTL},
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:set(Conn, Prefix, Key, Value, TTL), State};
handle_call({delete, Prefix, Key}, 
	    _From, State = #state{adapter=Adapter, connection = Conn}) ->
    {reply, Adapter:delete(Conn, Prefix, Key), State}.

{'fraction_non_alphanumeric': 0.16330728095433977, 'fraction_numerical': 0.00658165364047717, 'mean_word_length': 3.8063241106719365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5298927', 'n_tokens_mistral': 859, 'n_tokens_neox': 823, 'n_words': 169}