0

How can I find out what's inside the singleton cache ? I'm trying to find out why the cache is never hit? It always executes _M.introspect_access_token_req

local cache_id = "ati:" .. access_token
local res, err = singletons.cache:get(cache_id, { ttl = _M.conf.token_cache_time },
                _M.introspect_access_token_req, access_token)
function _M.introspect_access_token_req(access_token)
    local httpc = http:new()

    ngx.log(ngx.DEBUG, "APIGW-PLUGIN-ATI : Calling External service for Introspection ...")

    local res, err = httpc:request_uri(introspection_endpoint, {
        method = "POST",
        ssl_verify = false,
        body = "token_type_hint=access_token&token=" .. access_token .. "&client_id=" .. _M.conf.client_id .. "&client_secret=" .. _M.conf.client_secret,
        headers = { ["Content-Type"] = "application/x-www-form-urlencoded", }
    })

    ngx.log(ngx.DEBUG, "APIGW-PLUGIN-ATI : External service called")

    if not res then
        return { status = 0 }
    end
    if res.status ~= 200 then
        return { status = res.status }
    end
    return { id = "ati:" .. access_token, status = res.status, body = res.body }
end
Ôrel
  • 7,044
  • 3
  • 27
  • 46
Peter Claes
  • 285
  • 3
  • 9
  • 0.11.0 is 4 years old, current version is 2.4.1 – Ôrel Jun 23 '21 at 13:29
  • I know :-( , and how would it be in 2.4.1 ? – Peter Claes Jun 25 '21 at 20:31
  • For cache, you should use `ngx.shared` on 2.4.1, and use [get_keys](https://github.com/openresty/lua-nginx-module#ngxshareddictget_keys) – Ôrel Jun 26 '21 at 15:43
  • @Ôrel, can I use one of the default existing dictionaries (kong, kong_db_cache, ...) or do I have to define a custom one in nginx_conf ? Also I have multiple containers running Kong (same deployment, scale 2). How can I 'share' the cache between the 2 containers ? – Peter Claes Jul 05 '21 at 10:06
  • If you want to share cache between containers you need a third party, like redis. There is several example of using redis from kong – Ôrel Jul 05 '21 at 10:18

0 Answers0