feat: cache the registered domain once calculated

This commit is contained in:
Iain Learmonth 2025-05-04 16:11:09 +01:00
parent 61d66a5d45
commit a4ed2baf8b

View file

@ -81,6 +81,14 @@ end
function _M.get_registered_domain(domain)
if not domain or domain == "" then return nil end
local cache_key = "psl:" .. domain
local cache = ngx.shared.jasima_cache
local cached = cache:get(cache_key)
if cached then
return cached
end
local rules = load_psl()
if not rules then return nil end
@ -101,7 +109,9 @@ function _M.get_registered_domain(domain)
table.insert(reg_parts, domain_parts[i])
end
return table.concat(reg_parts, ".")
local result = table.concat(reg_parts, ".")
cache:set(cache_key, result, 86400 * 7) -- This is very unlikely to ever change
return result
end
return _M