feat: cache the registered domain once calculated
This commit is contained in:
parent
61d66a5d45
commit
a4ed2baf8b
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue