diff --git a/apisix/core/lrucache.lua b/apisix/core/lrucache.lua index c5765546e16bc..4cd3aba91ac4a 100644 --- a/apisix/core/lrucache.lua +++ b/apisix/core/lrucache.lua @@ -17,6 +17,7 @@ local lru_new = require("resty.lrucache").new local resty_lock = require("resty.lock") +local log = require("apisix.core.log") local tostring = tostring local ngx = ngx local get_phase = ngx.get_phase @@ -69,10 +70,11 @@ local function new_lru_fun(opts) local item_ttl = opts and opts.ttl or GLOBAL_TTL local item_release = opts and opts.release local invalid_stale = opts and opts.invalid_stale + local limit_concurrency = opts and opts.limit_concurrency local lru_obj = lru_new(item_count) return function (key, version, create_obj_fun, ...) - if not can_yield_phases[get_phase()] then + if not limit_concurrency or not can_yield_phases[get_phase()] then local cache_obj = fetch_valid_cache(lru_obj, invalid_stale, item_ttl, item_release, key, version) if cache_obj then @@ -99,6 +101,8 @@ local function new_lru_fun(opts) end local key_s = tostring(key) + log.info("try to lock with key ", key_s) + local elapsed, err = lock:lock(key_s) if not elapsed then return nil, "failed to acquire the lock: " .. err @@ -108,6 +112,7 @@ local function new_lru_fun(opts) nil, key, version) if cache_obj then lock:unlock() + log.info("unlock with key ", key_s) return cache_obj.val end @@ -116,6 +121,7 @@ local function new_lru_fun(opts) lru_obj:set(key, {val = obj, ver = version}, item_ttl) end lock:unlock() + log.info("unlock with key ", key_s) return obj, err end