Skip to content

Commit

Permalink
fix(ai): use # to concat route cache key parts (apache#8128)
Browse files Browse the repository at this point in the history
better performance and much clearer
  • Loading branch information
kingluo authored and Liu-Junlin committed Nov 4, 2022
1 parent e475d62 commit c65e6cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions apisix/plugins/ai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ local event = require("apisix.core.event")
local ipairs = ipairs
local pcall = pcall
local loadstring = loadstring
local encode_base64 = ngx.encode_base64

local get_cache_key_func
local get_cache_key_func_def_render
Expand All @@ -31,10 +30,10 @@ return function(ctx)
local var = ctx.var
return var.uri
{% if route_flags["methods"] then %}
.. "\0" .. var.method
.. "#" .. var.method
{% end %}
{% if route_flags["host"] then %}
.. "\0" .. var.host
.. "#" .. var.host
{% end %}
end
]]
Expand Down Expand Up @@ -68,7 +67,7 @@ end

local function ai_match(ctx)
local key = get_cache_key_func(ctx)
core.log.info("route cache key: ", core.log.delay_exec(encode_base64, key))
core.log.info("route cache key: ", key)
local ver = router.router_http.user_routes.conf_version
local route_cache = route_lrucache(key, ver,
match_route, ctx)
Expand Down
6 changes: 3 additions & 3 deletions t/plugin/ai.t
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ use ai plane to match route
--- response_body
done
--- error_log
route cache key: L2hlbGxv
route cache key: /hello
Expand Down Expand Up @@ -569,7 +569,7 @@ route cache key: L2hlbGxv
--- response_body
done
--- error_log
route cache key: L2hlbGxvAEdFVA==
route cache key: /hello#GET
Expand Down Expand Up @@ -619,4 +619,4 @@ route cache key: L2hlbGxvAEdFVA==
--- response_body
done
--- error_log
route cache key: L2hlbGxvAEdFVAAxMjcuMC4wLjE=
route cache key: /hello#GET#127.0.0.1

0 comments on commit c65e6cc

Please sign in to comment.