Skip to content

Commit

Permalink
refactor(router): simplify the functions of cache calculation (#11948)
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw authored and ADD-SP committed Mar 7, 2024
1 parent 673979f commit b4346ce
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,14 @@ do

local str_buf = buffer.new(64)

get_headers_key = function(headers)
local function get_headers_or_queries_key(values, lower_func)
str_buf:reset()

-- NOTE: DO NOT yield until str_buf:get()
for name, value in pairs(headers) do
local name = replace_dashes_lower(name)
for name, value in pairs(values) do
if lower_func then
name = lower_func(name)
end

if type(value) == "table" then
tb_sort(value)
Expand All @@ -614,20 +616,12 @@ do
return str_buf:get()
end

get_queries_key = function(queries)
str_buf:reset()

-- NOTE: DO NOT yield until str_buf:get()
for name, value in pairs(queries) do
if type(value) == "table" then
tb_sort(value)
value = tb_concat(value, ", ")
end

str_buf:putf("|%s=%s", name, value)
end
get_headers_key = function(headers)
return get_headers_or_queries_key(headers, replace_dashes_lower)
end

return str_buf:get()
get_queries_key = function(queries)
return get_headers_or_queries_key(queries)
end
end

Expand Down

0 comments on commit b4346ce

Please sign in to comment.