couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 12/17: FIXUP: Make the refresh timeout configurable
Date Mon, 10 Jul 2017 18:29:35 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch optimize-ddoc-cache
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit cd3687ac39ef42e602de5b8e35f169efc8d3fe1a
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Thu Jul 6 14:11:13 2017 -0500

    FIXUP: Make the refresh timeout configurable
---
 rel/overlay/etc/default.ini             |  8 ++++++++
 src/ddoc_cache/src/ddoc_cache_entry.erl | 13 ++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index eaa0801..be178e2 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -188,6 +188,14 @@ credentials = false
 ; List of accepted methods
 ; methods =
 
+; Configuration for the design document cache
+;[ddoc_cache]
+; The maximum number of entries to keep in the cache
+;max_size = 1000
+; The period each cache entry should wait before
+; automatically refreshing in milliseconds
+;refresh_timeout = 67000
+
 [x_frame_options]
 ; Settings same-origin will return X-Frame-Options: SAMEORIGIN.
 ; If same origin is set, it will ignore the hosts setting
diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl
index 79c3dcf..db5e0b1 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -123,11 +123,10 @@ init({Key, Default}) ->
     NewTs = os:timestamp(),
     true = ets:update_element(?CACHE, Key, Updates),
     true = ets:insert(?LRU, {{NewTs, Key, self()}}),
-    Msg = {'$gen_cast', refresh},
     St = #st{
         key = Key,
         val = {open_ok, {ok, Default}},
-        opener = erlang:send_after(?REFRESH_TIMEOUT, self(), Msg),
+        opener = start_timer(),
         waiters = undefined,
         ts = NewTs,
         accessed = 1
@@ -230,11 +229,9 @@ handle_info({'DOWN', _, _, Pid, Resp}, #st{key = Key, opener = Pid} =
St) ->
     case Resp of
         {open_ok, Key, {ok, Val}} ->
             update_cache(St, Val),
-            Msg = {'$gen_cast', refresh},
-            Timer = erlang:send_after(?REFRESH_TIMEOUT, self(), Msg),
             NewSt1 = St#st{
                 val = {open_ok, {ok, Val}},
-                opener = Timer
+                opener = start_timer()
             },
             NewSt2 = update_lru(NewSt1),
             if not is_list(St#st.waiters) -> ok; true ->
@@ -267,6 +264,12 @@ spawn_opener(Key) ->
     Pid.
 
 
+start_timer() ->
+    TimeOut = config:get_integer(
+            "ddoc_cache", "refresh_timeout", ?REFRESH_TIMEOUT),
+    erlang:send_after(TimeOut, self(), {'$gen_cast', refresh}).
+
+
 do_open(Key) ->
     try recover(Key) of
         Resp ->

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <commits@couchdb.apache.org>.

Mime
View raw message