couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benoit Chesneau <bchesn...@gmail.com>
Subject Re: svn commit: r1064076 - /couchdb/trunk/src/couchdb/couch_auth_cache.erl
Date Thu, 27 Jan 2011 12:25:24 GMT
here is a simpler patch, that just check if Counc is > 1:

---
 src/couchdb/couch_auth_cache.erl |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/couchdb/couch_auth_cache.erl b/src/couchdb/couch_auth_cache.erl
index 033e160..f14b91e 100644
--- a/src/couchdb/couch_auth_cache.erl
+++ b/src/couchdb/couch_auth_cache.erl
@@ -169,15 +169,7 @@ handle_call({new_max_cache_size, NewSize},
     {reply, ok, State#state{max_cache_size = NewSize}};

 handle_call({new_max_cache_size, NewSize}, _From, State) ->
-    lists:foreach(
-        fun(_) ->
-            LruTime = ets:last(?BY_ATIME),
-            [{LruTime, UserName}] = ets:lookup(?BY_ATIME, LruTime),
-            true = ets:delete(?BY_ATIME, LruTime),
-            true = ets:delete(?BY_USER, UserName)
-        end,
-        lists:seq(1, State#state.cache_size - NewSize)
-    ),
+    free_mru_cache_entries(State#state.cache_size - NewSize),
     {reply, ok, State#state{max_cache_size = NewSize, cache_size = NewSize}};

 handle_call({fetch, UserName}, _From, State) ->
@@ -223,7 +215,7 @@ terminate(_Reason, #state{db_notifier = Notifier}) ->

 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
-
+

 clear_cache(State) ->
     exec_if_auth_db(fun(AuthDb) -> catch couch_db:close(AuthDb) end),
@@ -244,6 +236,16 @@ add_cache_entry(UserName, Credentials, ATime, State) ->
     State#state{cache_size = couch_util:get_value(size, ets:info(?BY_USER))}.


+free_mru_cache_entries(Count) when Count > 1 ->
+    LruTime = ets:last(?BY_ATIME),
+    [{LruTime, UserName}] = ets:lookup(?BY_ATIME, LruTime),
+    true = ets:delete(?BY_ATIME, LruTime),
+    true = ets:delete(?BY_USER, UserName),
+    free_mru_cache_entries(Count-1);
+free_mru_cache_entries(_) ->
+    ok.
+
+
 free_mru_cache_entry() ->
     case ets:last(?BY_ATIME) of
     '$end_of_table' ->
-- 
1.7.3.4

Mime
View raw message