当前位置: 首页 > 工具软件 > LRUCache > 使用案例 >

lrucache

齐锐进
2023-12-01

local _M = {}

--local lrucache = require "resty.lrucache.pureffi"
local lrucache = require "resty.lrucache"

-- we need to initialize the cache on the lua module level so that
-- it can be shared by all the requests served by each nginx worker process:
local c = lrucache.new(200) -- 如果是2,则下面的代码,dog的值会被cat和x覆盖
if not c then
return error("failed to create the cache: " .. (err or "unknown"))
end

function _M.go()
c:set("dog", 32)
c:set("cat", 56)
ngx.say("dog: ", c:get("dog"))
ngx.say("cat: ", c:get("cat"))
c:delete("cat")
ngx.say("cat: ", c:get("cat"))

c:set("x", 101, 2) -- expire in 1 sec
ngx.sleep(1)
ngx.say("x: ", c:get("x"))
ngx.sleep(1)
ngx.say("x: ", c:get("x"))
end

_M.go()

return _M


dog: 32
cat: 56
cat: nil
x: 101
x: nil101
 类似资料:

相关阅读

相关文章

相关问答