diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua index 772bd3832ed3..2a2aee6f7a38 100644 --- a/apisix/plugins/ext-plugin/init.lua +++ b/apisix/plugins/ext-plugin/init.lua @@ -65,11 +65,16 @@ local type = type local events_list -local lrucache = core.lrucache.new({ - type = "plugin", - invalid_stale = true, - ttl = helper.get_conf_token_cache_time(), -}) + +local function new_lrucache() + return core.lrucache.new({ + type = "plugin", + invalid_stale = true, + ttl = helper.get_conf_token_cache_time(), + }) +end +local lrucache = new_lrucache() + local shdict_name = "ext-plugin" local shdict = ngx.shared[shdict_name] @@ -668,17 +673,14 @@ rpc_call = function (ty, conf, ctx, ...) end -local function create_lrucache() +local function recreate_lrucache() flush_token() if lrucache then core.log.warn("flush conf token lrucache") end - lrucache = core.lrucache.new({ - type = "plugin", - ttl = helper.get_conf_token_cache_time(), - }) + lrucache = new_lrucache() end @@ -702,7 +704,7 @@ function _M.communicate(conf, ctx, plugin_name) end core.log.warn("refresh cache and try again") - create_lrucache() + recreate_lrucache() end core.log.error(err) @@ -799,7 +801,7 @@ function _M.init_worker() ) -- flush cache when runner exited - events.register(create_lrucache, events_list._source, events_list.runner_exit) + events.register(recreate_lrucache, events_list._source, events_list.runner_exit) -- note that the runner is run under the same user as the Nginx master if process.type() == "privileged agent" then