Skip to content

Commit

Permalink
Average 60 sec hit count with 30 sec for windowed hit count
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjustus committed Feb 11, 2014
1 parent bf9394c commit 242eaef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/luchador/storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ function Storage:set(key, val, ttl, is_metadata)
end

function Storage:incr_hit_count(key, ttl)
total_key = key .. 'hits'
window_key = key .. 'whits'
local total_key = key .. 'hits'
local window_key = key .. 'whits'
local count = self:incr_or_set(total_key, ttl)

-- hit window of 30 seconds for local cache
-- hit window of 60 seconds for local cache
local long_window_count = self:incr_or_set(window_key .. 'l', 60)
local window_count = self:incr_or_set(window_key, 30)

ngx.header['X-Hit-Count'] = count
self.windowed_hit_count = window_count
self.windowed_hit_count = (window_count + long_window_count) / 2
end

function Storage:incr_or_set(key, ttl)
Expand Down

0 comments on commit 242eaef

Please sign in to comment.