From c65e6cc0bd11b1e85c23352944eb7c8743027b16 Mon Sep 17 00:00:00 2001 From: jinhua luo Date: Thu, 20 Oct 2022 17:09:56 +0800 Subject: [PATCH] fix(ai): use # to concat route cache key parts (#8128) better performance and much clearer --- apisix/plugins/ai.lua | 7 +++---- t/plugin/ai.t | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/apisix/plugins/ai.lua b/apisix/plugins/ai.lua index 6b60aac29c1f..cb69f59a7c68 100644 --- a/apisix/plugins/ai.lua +++ b/apisix/plugins/ai.lua @@ -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 @@ -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 ]] @@ -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) diff --git a/t/plugin/ai.t b/t/plugin/ai.t index 3c0cd62d97e0..9415771ab629 100644 --- a/t/plugin/ai.t +++ b/t/plugin/ai.t @@ -520,7 +520,7 @@ use ai plane to match route --- response_body done --- error_log -route cache key: L2hlbGxv +route cache key: /hello @@ -569,7 +569,7 @@ route cache key: L2hlbGxv --- response_body done --- error_log -route cache key: L2hlbGxvAEdFVA== +route cache key: /hello#GET @@ -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