anchor.diff:  do_delete_permission(State = #state{cache = Cache}, PermissionModel) ->
     case em_storage:delete_permission(PermissionModel) of
       {ok, Permission} ->
  -      case ets:delete(Cache, Permission#permission.id) of
  -        true ->
  -          {reply, {ok, Permission}, State};
  -        false -> {reply, {error, <<"Error sync in permissions cache">>}, State}
  +      Match = ets:fun2ms(fun(#permission{userId = UserId, deviceId = DeviceId}) when (UserId =:= Permission#permission.userId) and (DeviceId =:= Permission#permission.deviceId) -> true end),
  +      case ets:select_delete(Cache, Match) of
  +        0 ->
  +          {reply, {error, <<"Error sync in permissions cache">>}, State};
  +        _ ->
  +          {reply, {ok, Permission}, State}
         end;
       Reason ->
         {reply, Reason, State}
  
positive.code:   {noreply, NewState :: #state{}, timeout() | hibernate} |
    {stop, Reason :: term(), Reply :: term(), NewState :: #state{}} |
    {stop, Reason :: term(), NewState :: #state{}}).
  handle_call({get, Id}, _From, State) when is_integer(Id) ->
    do_get_permissions_by_user_id(State, Id);
  handle_call({create, Permission}, _From, State) ->
  
negative.code: %%%===================================================================
  %%% Internal functions
  %%%===================================================================
  do_get_permissions(State = #state{cache = Cache}) ->
    {reply, {ok, ets:tab2list(Cache)}, State}.
  
  do_get_permissions_by_user_id(State = #state{cache = Cache}, SearchUserId) ->
    Match = ets:fun2ms(fun(Permission = #permission{userId = UserId}) when UserId =:= SearchUserId -> Permission end),
    {reply, {ok, ets:select(Cache, Match)}, State}.
  