fix: json encode psl rules to cache between requests
This commit is contained in:
parent
ecf5e28086
commit
99f7a5d635
1 changed files with 4 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
local cjson = require "cjson"
|
||||
local http = require "resty.http"
|
||||
|
||||
local _M = {}
|
||||
|
@ -26,10 +27,11 @@ end
|
|||
local function load_psl()
|
||||
local cache = ngx.shared.jasima_cache
|
||||
local cached = cache:get("psl")
|
||||
if cached then return cached end
|
||||
if cached then return cjson.decode(cached) end
|
||||
ngx.log(ngx.DEBUG, "Cache miss on public suffix list")
|
||||
local rules, err = fetch_psl()
|
||||
if rules then
|
||||
cache:set("psl", rules, 86400 * 7) -- 1 week
|
||||
cache:set("psl", cjson.encode(rules), 86400 * 7) -- 1 week
|
||||
return rules
|
||||
else
|
||||
ngx.log(ngx.ERR, err or "Unknown error loading PSL")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue