Skip to content

Commit

Permalink
refactor(router/rpc): cache the result of parse_method_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Apr 28, 2024
1 parent 7b5add3 commit dffa4e4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kong/clustering/rpc/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local _M = {}
local pl_stringx = require("pl.stringx")
local cjson = require("cjson")
local snappy = require("resty.snappy")
local lrucache = require("resty.lrucache")


local string_sub = string.sub
Expand All @@ -13,13 +14,26 @@ local snappy_compress = snappy.compress
local snappy_uncompress = snappy.uncompress


local cap_names = lrucache.new(100)


function _M.parse_method_name(method)
local cap = cap_names:get(method)

if cap then
return cap[1], cap[2]
end

local pos = rfind(method, ".")
if not pos then
return nil, "not a valid method name"
end

return method:sub(1, pos - 1), method:sub(pos + 1)
local cap = { method:sub(1, pos - 1), method:sub(pos + 1) }

cap_names:set(method, cap)

return cap[1], cap[2]
end


Expand Down

0 comments on commit dffa4e4

Please sign in to comment.