When implementing caching, make coherence and invalidation explicit and configuration-driven:
Example pattern (versioned + conditional reload):
-- cache state
local upstream_version = 0
local all_upstreams
local function reset_all_upstreams()
-- recompute and repopulate shared/local state
-- ...
upstream_version = new_upstream_version
all_upstreams = upstreams_dict
return true
end
reload_all_upstreams = function()
-- in strict consistency mode, skip reloads entirely
if kong.configuration.upstream_consistency == "strict" then
return true
end
-- otherwise reload only when upstreams changed
if upstream_version == new_upstream_version then
return true
end
return reset_all_upstreams()
end
Checklist to apply during review: 1) Does any config imply strict correctness? If yes, is lazy reload/invalidation disabled accordingly? 2) Is the cache shared across workers (or otherwise proven consistent)? 3) Is TTL aligned with how entries actually become invalid (TTL vs cascade delete vs explicit version updates)?