# HG changeset patch # User Matthew Wild # Date 1449154469 0 # Node ID 8ab8093589226dcf25b1d28226db9ce9de69f974 # Parent 1c2c3d913172efbec8fd392aa74fab41b93b48c9 net.http.server: Use new util.cache to remember wildcard event handlers diff -r 1c2c3d913172 -r 8ab809358922 net/http/server.lua --- a/net/http/server.lua Thu Dec 03 14:47:47 2015 +0000 +++ b/net/http/server.lua Thu Dec 03 14:54:29 2015 +0000 @@ -27,7 +27,10 @@ return wildcard_event:sub(1, -2) == event:sub(1, #wildcard_event-1); end -local recent_wildcard_events, max_cached_wildcard_events = {}, 10000; +local _handlers = events._handlers; +local recent_wildcard_events = cache.new(10000, function (key, value) + rawset(_handlers, key, nil); +end); local event_map = events._event_map; setmetatable(events._handlers, { @@ -62,10 +65,7 @@ end rawset(handlers, curr_event, handlers_array); if not event_map[curr_event] then -- Only wildcard handlers match, if any - table.insert(recent_wildcard_events, curr_event); - if #recent_wildcard_events > max_cached_wildcard_events then - rawset(handlers, table.remove(recent_wildcard_events, 1), nil); - end + recent_wildcard_events:set(curr_event, true); end return handlers_array; end;