Disable cache resurrection for plugins

Hi

I have a setup where I want the user to authenticate for an API. I wrote a plugin for that and it works as expected except for the following scenario:

If the user is authenticated and is cached after the cache expires and the internet is disconnected, a request on the protected route logs the following

[warn] 30#0: *301 [lua] mlcache.lua:763: get(): callback returned an error (failed to call introspection endpoint: [cosocket] DNS resolution failed: dns server error: 3 name error. Tried: ["(short)<API_ENDPOINT>:(na) - cache-miss","<API_ENDPOINT>:33 - cache-miss/scheduled/querying/dns server error: 3 name error","API_ENDPOINT>:1 - cache-miss/scheduled/querying/dns server error: 3 name error","API_ENDPOINT>:5 - cache-miss/scheduled/querying/dns server error: 3 name error"]) but stale value found in shm will be resurrected for 30s (resurrect_ttl), client: 192.168.128.1, server: kong, request: "POST / HTTP/1.1", host: "localhost:3000"

Since the stale value is found in shm and is resurrected, the API call goes through even when it should fail.

Is there a way to:

  1. Disable the cache resurrection OR
  2. Remove the stale values from the cache?

Hello,

If you are using the kong.cache instance (which is reserved for Kong core’s cache), then that instance has resurrect_ttl specified (from kong.conf), see mlcache’s documentation for more details. If this option is specified at the instance level, it can be overridden in get() but I don’t believe that it can be disabled entirely for a particular get() call; something to double check in the mlcache code.

It appears that you have two options:

  1. Use your own mlcache instance which you can configure for your own use-case.
  2. Contribute a tiny feature to mlcache so that calls to get() could skip resurrection somehow even if it is enabled in the instance (maybe specifying resurrect_ttl = 0 in get()? Something to be debated elsewhere).

Hope that helps.