Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai): use # to concat route cache key parts #8128

Merged
merged 2 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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